@bastani/atomic 0.9.37 → 0.9.38-alpha.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/CHANGELOG.md +18 -0
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/CHANGELOG.md +6 -0
- package/dist/builtin/workflows/builtin/{chunk-rhkg3d8e.js → chunk-3n2bnz64.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-3xffzzbg.js → chunk-ad83gc5p.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-7fvrnzhb.js → chunk-x6az1sxp.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-8c3ae7tt.js → chunk-ymwq372z.js} +1 -1
- package/dist/builtin/workflows/builtin/goal.js +2 -2
- package/dist/builtin/workflows/builtin/index.js +3 -3
- package/dist/builtin/workflows/builtin/ralph.js +2 -2
- package/dist/builtin/workflows/package.json +1 -1
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +7 -0
- package/dist/builtin/workflows/src/index.js +7 -0
- package/dist/cli/credential-print.d.ts.map +1 -1
- package/dist/cli/credential-print.js +4 -4
- package/dist/cli/credential-print.js.map +1 -1
- package/dist/core/agent-session-extension-bindings.d.ts +1 -1
- package/dist/core/agent-session-extension-bindings.d.ts.map +1 -1
- package/dist/core/agent-session-extension-bindings.js +19 -5
- package/dist/core/agent-session-extension-bindings.js.map +1 -1
- package/dist/core/agent-session-methods.d.ts +2 -2
- package/dist/core/agent-session-methods.d.ts.map +1 -1
- package/dist/core/agent-session-methods.js.map +1 -1
- package/dist/core/agent-session-retry.js +1 -1
- package/dist/core/agent-session-retry.js.map +1 -1
- package/dist/core/agent-session-state.d.ts +4 -6
- package/dist/core/agent-session-state.d.ts.map +1 -1
- package/dist/core/agent-session-state.js +13 -8
- package/dist/core/agent-session-state.js.map +1 -1
- package/dist/core/agent-session-tool-registry.d.ts.map +1 -1
- package/dist/core/agent-session-tool-registry.js +3 -1
- package/dist/core/agent-session-tool-registry.js.map +1 -1
- package/dist/core/agent-session.js +1 -1
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/export-html/template-js/message-tools.js +20 -7
- package/dist/core/export-html/template-js/tree-filter-render.js +1 -9
- package/dist/core/export-html/template.js +21 -16
- package/dist/core/model-config.d.ts +9 -9
- package/dist/core/model-fallback-failures.d.ts.map +1 -1
- package/dist/core/model-fallback-failures.js +3 -1
- package/dist/core/model-fallback-failures.js.map +1 -1
- package/dist/core/model-resolver-cli.d.ts +2 -0
- package/dist/core/model-resolver-cli.d.ts.map +1 -1
- package/dist/core/model-resolver-cli.js +47 -143
- package/dist/core/model-resolver-cli.js.map +1 -1
- package/dist/core/model-resolver-patterns.d.ts +48 -22
- package/dist/core/model-resolver-patterns.d.ts.map +1 -1
- package/dist/core/model-resolver-patterns.js +154 -105
- package/dist/core/model-resolver-patterns.js.map +1 -1
- package/dist/core/model-resolver-scope.d.ts +6 -9
- package/dist/core/model-resolver-scope.d.ts.map +1 -1
- package/dist/core/model-resolver-scope.js +51 -53
- package/dist/core/model-resolver-scope.js.map +1 -1
- package/dist/core/model-resolver-types.d.ts +0 -6
- package/dist/core/model-resolver-types.d.ts.map +1 -1
- package/dist/core/model-resolver-types.js.map +1 -1
- package/dist/core/model-resolver.d.ts +3 -2
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +1 -1
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/prompt-templates.d.ts.map +1 -1
- package/dist/core/prompt-templates.js +6 -2
- package/dist/core/prompt-templates.js.map +1 -1
- package/dist/core/retry-policy.d.ts +5 -2
- package/dist/core/retry-policy.d.ts.map +1 -1
- package/dist/core/retry-policy.js +4 -3
- package/dist/core/retry-policy.js.map +1 -1
- package/dist/core/settings-manager-basic-accessors.d.ts +1 -0
- package/dist/core/settings-manager-basic-accessors.d.ts.map +1 -1
- package/dist/core/settings-manager-basic-accessors.js +1 -0
- package/dist/core/settings-manager-basic-accessors.js.map +1 -1
- package/dist/core/tools/malformed-tool-arguments.d.ts +3 -0
- package/dist/core/tools/malformed-tool-arguments.d.ts.map +1 -0
- package/dist/core/tools/malformed-tool-arguments.js +23 -0
- package/dist/core/tools/malformed-tool-arguments.js.map +1 -0
- package/dist/core/tools/render-utils.d.ts +2 -0
- package/dist/core/tools/render-utils.d.ts.map +1 -1
- package/dist/core/tools/render-utils.js +19 -0
- package/dist/core/tools/render-utils.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/main-session-options.d.ts.map +1 -1
- package/dist/main-session-options.js +1 -0
- package/dist/main-session-options.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector-content.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector-content.js +2 -9
- package/dist/modes/interactive/components/tree-selector-content.js.map +1 -1
- package/docs/docs.json +2 -1
- package/docs/extensions/ui.md +10 -0
- package/docs/llama-cpp.md +2 -0
- package/docs/models/reference.md +7 -0
- package/docs/nvidia-rtx-llama-cpp.md +101 -0
- package/docs/prompt-templates.md +2 -0
- package/docs/providers.md +4 -0
- package/docs/reference/cli.md +3 -3
- package/docs/sessions.md +4 -0
- package/docs/settings.md +3 -3
- package/docs/tools.md +2 -0
- package/docs/workflows/api-reference.md +2 -0
- package/examples/extensions/minimal-mode.ts +1 -8
- package/examples/extensions/subagent/display.ts +4 -6
- package/npm-shrinkwrap.json +32 -32
- package/package.json +3 -3
- package/schemas/models.schema.json +5 -5
|
@@ -1,74 +1,172 @@
|
|
|
1
1
|
import { isValidThinkingLevel } from "../cli/args.js";
|
|
2
2
|
import { normalizeModelReference } from "./azure-provider-compat.js";
|
|
3
3
|
import { defaultModelPerProvider } from "./model-resolver-defaults.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
function splitThinkingSuffix(text) {
|
|
5
|
+
const colonIndex = text.lastIndexOf(":");
|
|
6
|
+
const suffix = text.substring(colonIndex + 1);
|
|
7
|
+
if (colonIndex <= 0 || !isValidThinkingLevel(suffix))
|
|
8
|
+
return undefined;
|
|
9
|
+
return { base: text.substring(0, colonIndex), thinkingLevel: suffix };
|
|
10
|
+
}
|
|
11
|
+
function splitProviderPrefix(text, models) {
|
|
12
|
+
const slashIndex = text.indexOf("/");
|
|
13
|
+
if (slashIndex === -1)
|
|
14
|
+
return undefined;
|
|
15
|
+
const prefix = text.substring(0, slashIndex).trim().toLowerCase();
|
|
16
|
+
const modelText = text.substring(slashIndex + 1).trim();
|
|
17
|
+
if (!prefix || !modelText)
|
|
18
|
+
return undefined;
|
|
19
|
+
const provider = models.find((model) => model.provider.toLowerCase() === prefix)?.provider;
|
|
20
|
+
return provider ? { provider, modelText } : undefined;
|
|
21
|
+
}
|
|
22
|
+
/** Duplicate entries from one provider must not look like several providers. */
|
|
23
|
+
function uniqueByReference(models) {
|
|
24
|
+
const seen = new Set();
|
|
25
|
+
return models.filter((model) => {
|
|
26
|
+
const key = `${model.provider.toLowerCase()}/${model.id.toLowerCase()}`;
|
|
27
|
+
if (seen.has(key))
|
|
28
|
+
return false;
|
|
29
|
+
seen.add(key);
|
|
10
30
|
return true;
|
|
11
|
-
|
|
12
|
-
return !datePattern.test(id);
|
|
31
|
+
});
|
|
13
32
|
}
|
|
14
33
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* When matching by bare id, ambiguous matches across providers are rejected.
|
|
34
|
+
* `usable` only breaks ties between providers, so a unique match resolves even without credentials
|
|
35
|
+
* (`--api-key` first-time setup).
|
|
18
36
|
*/
|
|
19
|
-
export function
|
|
20
|
-
const
|
|
21
|
-
if (!
|
|
22
|
-
return
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
if (
|
|
27
|
-
return
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
37
|
+
export function resolveModelReference(request, models, usable) {
|
|
38
|
+
const text = normalizeModelReference(request.text.trim());
|
|
39
|
+
if (!text)
|
|
40
|
+
return { status: "not-found" };
|
|
41
|
+
const constraint = request.provider?.toLowerCase();
|
|
42
|
+
const pool = constraint ? models.filter((model) => model.provider.toLowerCase() === constraint) : models;
|
|
43
|
+
const result = resolveText(text, request, pool, usable);
|
|
44
|
+
if (result.status !== "not-found")
|
|
45
|
+
return result;
|
|
46
|
+
const split = splitProviderPrefix(text, pool);
|
|
47
|
+
const anchor = constraint ? pool[0] : pool.find((model) => model.provider === split?.provider);
|
|
48
|
+
if (!anchor)
|
|
49
|
+
return result;
|
|
50
|
+
const modelText = split?.modelText ?? text;
|
|
51
|
+
const suffix = request.thinkingSuffix === "none" ? undefined : splitThinkingSuffix(modelText);
|
|
52
|
+
return {
|
|
53
|
+
status: "not-found",
|
|
54
|
+
target: {
|
|
55
|
+
provider: anchor.provider,
|
|
56
|
+
providerModels: [anchor, ...pool.filter((model) => model.provider === anchor.provider && model !== anchor)],
|
|
57
|
+
modelText,
|
|
58
|
+
modelId: suffix?.base ?? modelText,
|
|
59
|
+
thinkingLevel: suffix?.thinkingLevel,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/** Exact `provider/id` or bare id lookup without thinking suffixes or fuzzy matching. */
|
|
64
|
+
export function findExactModelReferenceMatch(modelReference, models) {
|
|
65
|
+
const result = resolveModelReference({ text: modelReference, thinkingSuffix: "none", fuzzy: false }, models, () => true);
|
|
66
|
+
return result.status === "resolved" ? result.model : undefined;
|
|
67
|
+
}
|
|
68
|
+
function resolveText(text, request, pool, usable) {
|
|
69
|
+
const reference = selectReference(text, pool, request.fuzzy, usable);
|
|
70
|
+
if (reference)
|
|
71
|
+
return reference;
|
|
72
|
+
if (request.fuzzy) {
|
|
73
|
+
const fuzzy = selectFuzzy(fuzzyMatches(text, pool), usable);
|
|
74
|
+
if (fuzzy)
|
|
75
|
+
return fuzzy;
|
|
31
76
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
if (providerMatches.length > 1) {
|
|
43
|
-
return undefined;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
77
|
+
if (request.thinkingSuffix === "none")
|
|
78
|
+
return { status: "not-found" };
|
|
79
|
+
const thinking = splitThinkingSuffix(text);
|
|
80
|
+
if (thinking) {
|
|
81
|
+
const inner = resolveText(thinking.base, request, pool, usable);
|
|
82
|
+
if (inner.status === "not-found")
|
|
83
|
+
return inner;
|
|
84
|
+
// An inner warning means an invalid inner suffix, which discards the thinking level
|
|
85
|
+
return { ...inner, thinkingLevel: inner.warning ? undefined : thinking.thinkingLevel };
|
|
46
86
|
}
|
|
47
|
-
|
|
48
|
-
|
|
87
|
+
// Keep an invalid suffix as part of the id and fail, rather than resolve a different model
|
|
88
|
+
if (request.thinkingSuffix === "strict")
|
|
89
|
+
return { status: "not-found" };
|
|
90
|
+
const colonIndex = text.lastIndexOf(":");
|
|
91
|
+
if (colonIndex <= 0)
|
|
92
|
+
return { status: "not-found" };
|
|
93
|
+
const suffix = text.substring(colonIndex + 1);
|
|
94
|
+
const inner = resolveText(text.substring(0, colonIndex), request, pool, usable);
|
|
95
|
+
if (inner.status === "not-found")
|
|
96
|
+
return inner;
|
|
97
|
+
return {
|
|
98
|
+
...inner,
|
|
99
|
+
thinkingLevel: undefined,
|
|
100
|
+
warning: `Invalid thinking level "${suffix}" in pattern "${text}". Using default instead.`,
|
|
101
|
+
};
|
|
49
102
|
}
|
|
50
103
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
104
|
+
* `provider/rest` is only a hint: the whole text may also be a model id on another provider, such as
|
|
105
|
+
* gateway id `zai/glm-5` or commandcode id `xiaomi/mimo-v2.5-pro`. The named provider wins when usable,
|
|
106
|
+
* since that is what the syntax usually means; otherwise a sole usable raw match wins, since the named
|
|
107
|
+
* provider could not serve the request. An unusable named match is still preferred over unusable raw
|
|
108
|
+
* matches, so `--api-key` can set up the named provider.
|
|
53
109
|
*/
|
|
54
|
-
function
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
110
|
+
function selectReference(text, pool, fuzzy, usable) {
|
|
111
|
+
const lowerText = text.toLowerCase();
|
|
112
|
+
const raw = uniqueByReference(pool.filter((model) => model.id.toLowerCase() === lowerText));
|
|
113
|
+
const split = splitProviderPrefix(text, pool);
|
|
114
|
+
let named;
|
|
115
|
+
if (split) {
|
|
116
|
+
const providerModels = pool.filter((model) => model.provider === split.provider);
|
|
117
|
+
const lowerModelText = split.modelText.toLowerCase();
|
|
118
|
+
// The provider's own literal id (OpenRouter's `openrouter/free`) beats its fuzzy matches
|
|
119
|
+
named =
|
|
120
|
+
providerModels.find((model) => model.id.toLowerCase() === lowerModelText) ??
|
|
121
|
+
raw.find((model) => model.provider === split.provider) ??
|
|
122
|
+
(fuzzy ? bestFuzzyMatch(fuzzyMatches(split.modelText, providerModels)) : undefined);
|
|
58
123
|
}
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
if (
|
|
124
|
+
const others = raw.filter((model) => model !== named);
|
|
125
|
+
const candidates = named ? [named, ...others] : others;
|
|
126
|
+
if (candidates.length === 0)
|
|
62
127
|
return undefined;
|
|
128
|
+
if (new Set(candidates.map((model) => model.provider)).size === 1) {
|
|
129
|
+
return { status: "resolved", model: candidates[0] };
|
|
63
130
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return
|
|
131
|
+
if (named && usable(named.provider))
|
|
132
|
+
return { status: "resolved", model: named };
|
|
133
|
+
const usableOthers = others.filter((model) => usable(model.provider));
|
|
134
|
+
if (usableOthers.length === 1)
|
|
135
|
+
return { status: "resolved", model: usableOthers[0] };
|
|
136
|
+
if (usableOthers.length === 0 && named)
|
|
137
|
+
return { status: "resolved", model: named };
|
|
138
|
+
return { status: "ambiguous", candidates, usableCount: usableOthers.length };
|
|
139
|
+
}
|
|
140
|
+
function fuzzyMatches(text, models) {
|
|
141
|
+
const lowerText = text.toLowerCase();
|
|
142
|
+
return models.filter((model) => model.id.toLowerCase().includes(lowerText) || model.name?.toLowerCase().includes(lowerText));
|
|
143
|
+
}
|
|
144
|
+
function selectFuzzy(matches, usable) {
|
|
145
|
+
if (matches.length === 0)
|
|
146
|
+
return undefined;
|
|
147
|
+
const multipleProviders = new Set(matches.map((model) => model.provider)).size > 1;
|
|
148
|
+
const usableMatches = multipleProviders ? matches.filter((model) => usable(model.provider)) : [];
|
|
149
|
+
const pool = usableMatches.length > 0 ? usableMatches : matches;
|
|
150
|
+
const best = bestFuzzyMatch(pool);
|
|
151
|
+
if (!best)
|
|
152
|
+
return undefined;
|
|
153
|
+
// The same id on several providers would otherwise be decided by catalog order
|
|
154
|
+
const tied = uniqueByReference(pool.filter((model) => model.id === best.id));
|
|
155
|
+
if (new Set(tied.map((model) => model.provider)).size === 1)
|
|
156
|
+
return { status: "resolved", model: best };
|
|
157
|
+
return {
|
|
158
|
+
status: "ambiguous",
|
|
159
|
+
candidates: tied,
|
|
160
|
+
usableCount: usableMatches.length > 0 ? tied.length : 0,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
/** Prefer aliases (`claude-sonnet-4-5`) over dated versions (`claude-sonnet-4-5-20250929`), then the latest. */
|
|
164
|
+
function bestFuzzyMatch(matches) {
|
|
165
|
+
const aliases = matches.filter((model) => isAlias(model.id));
|
|
166
|
+
return [...(aliases.length > 0 ? aliases : matches)].sort((a, b) => b.id.localeCompare(a.id))[0];
|
|
167
|
+
}
|
|
168
|
+
function isAlias(id) {
|
|
169
|
+
return id.endsWith("-latest") || !/-\d{8}$/.test(id);
|
|
72
170
|
}
|
|
73
171
|
export function buildFallbackModel(provider, modelId, availableModels) {
|
|
74
172
|
const providerModels = availableModels.filter((m) => m.provider === provider);
|
|
@@ -86,53 +184,4 @@ export function buildFallbackModel(provider, modelId, availableModels) {
|
|
|
86
184
|
contextWindow: fallbackContextWindow,
|
|
87
185
|
};
|
|
88
186
|
}
|
|
89
|
-
/**
|
|
90
|
-
* Parse a pattern to extract model and thinking level.
|
|
91
|
-
* Handles models with colons in their IDs (e.g., OpenRouter's :exacto suffix).
|
|
92
|
-
*
|
|
93
|
-
* Algorithm:
|
|
94
|
-
* 1. Try to match full pattern as a model
|
|
95
|
-
* 2. If found, return it with "off" thinking level
|
|
96
|
-
* 3. If not found and has colons, split on last colon:
|
|
97
|
-
* - If suffix is valid thinking level, use it and recurse on prefix
|
|
98
|
-
* - If suffix is invalid, warn and recurse on prefix with "off"
|
|
99
|
-
*
|
|
100
|
-
* @internal Exported for testing
|
|
101
|
-
*/
|
|
102
|
-
export function parseModelPattern(pattern, availableModels, options) {
|
|
103
|
-
const exactMatch = tryMatchModel(pattern, availableModels);
|
|
104
|
-
if (exactMatch) {
|
|
105
|
-
return { model: exactMatch, thinkingLevel: undefined, warning: undefined };
|
|
106
|
-
}
|
|
107
|
-
const lastColonIndex = pattern.lastIndexOf(":");
|
|
108
|
-
if (lastColonIndex === -1) {
|
|
109
|
-
return { model: undefined, thinkingLevel: undefined, warning: undefined };
|
|
110
|
-
}
|
|
111
|
-
const prefix = pattern.substring(0, lastColonIndex);
|
|
112
|
-
const suffix = pattern.substring(lastColonIndex + 1);
|
|
113
|
-
if (isValidThinkingLevel(suffix)) {
|
|
114
|
-
const result = parseModelPattern(prefix, availableModels, options);
|
|
115
|
-
if (result.model) {
|
|
116
|
-
return {
|
|
117
|
-
model: result.model,
|
|
118
|
-
thinkingLevel: result.warning ? undefined : suffix,
|
|
119
|
-
warning: result.warning,
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
return result;
|
|
123
|
-
}
|
|
124
|
-
const allowFallback = options?.allowInvalidThinkingLevelFallback ?? true;
|
|
125
|
-
if (!allowFallback) {
|
|
126
|
-
return { model: undefined, thinkingLevel: undefined, warning: undefined };
|
|
127
|
-
}
|
|
128
|
-
const result = parseModelPattern(prefix, availableModels, options);
|
|
129
|
-
if (result.model) {
|
|
130
|
-
return {
|
|
131
|
-
model: result.model,
|
|
132
|
-
thinkingLevel: undefined,
|
|
133
|
-
warning: `Invalid thinking level "${suffix}" in pattern "${pattern}". Using default instead.`,
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
return result;
|
|
137
|
-
}
|
|
138
187
|
//# sourceMappingURL=model-resolver-patterns.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-resolver-patterns.js","sourceRoot":"","sources":["../../src/core/model-resolver-patterns.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAGvE;;;GAGG;AACH,SAAS,OAAO,CAAC,EAAU;IAC1B,IAAI,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC;QAAE,OAAO,IAAI,CAAC;IAExC,MAAM,WAAW,GAAG,SAAS,CAAC;IAC9B,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC9B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,4BAA4B,CAC3C,cAAsB,EACtB,eAA6B;IAE7B,MAAM,gBAAgB,GAAG,uBAAuB,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,CAAC;IACxE,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACvB,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,MAAM,mBAAmB,GAAG,gBAAgB,CAAC,WAAW,EAAE,CAAC;IAC3D,MAAM,gBAAgB,GAAG,eAAe,CAAC,MAAM,CAC9C,CA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C;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["import type { Api, Model } from \"@bastani/pi-ai/compat\";\nimport type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport { isValidThinkingLevel } from \"../cli/args.ts\";\nimport { normalizeModelReference } from \"./azure-provider-compat.js\";\nimport { defaultModelPerProvider } from \"./model-resolver-defaults.ts\";\nimport type { ParsedModelResult } from \"./model-resolver-types.ts\";\n\n/**\n * Helper to check if a model ID looks like an alias (no date suffix)\n * Dates are typically in format: -20241022 or -20250929\n */\nfunction isAlias(id: string): boolean {\n\tif (id.endsWith(\"-latest\")) return true;\n\n\tconst datePattern = /-\\d{8}$/;\n\treturn !datePattern.test(id);\n}\n\n/**\n * Find an exact model reference match.\n * Supports either a bare model id or a canonical provider/modelId reference.\n * When matching by bare id, ambiguous matches across providers are rejected.\n */\nexport function findExactModelReferenceMatch(\n\tmodelReference: string,\n\tavailableModels: Model<Api>[],\n): Model<Api> | undefined {\n\tconst trimmedReference = normalizeModelReference(modelReference.trim());\n\tif (!trimmedReference) {\n\t\treturn undefined;\n\t}\n\n\tconst normalizedReference = trimmedReference.toLowerCase();\n\tconst canonicalMatches = availableModels.filter(\n\t\t(model) => `${model.provider}/${model.id}`.toLowerCase() === normalizedReference,\n\t);\n\tif (canonicalMatches.length === 1) {\n\t\treturn canonicalMatches[0];\n\t}\n\tif (canonicalMatches.length > 1) {\n\t\treturn undefined;\n\t}\n\n\tconst slashIndex = trimmedReference.indexOf(\"/\");\n\tif (slashIndex !== -1) {\n\t\tconst provider = trimmedReference.substring(0, slashIndex).trim();\n\t\tconst modelId = trimmedReference.substring(slashIndex + 1).trim();\n\t\tif (provider && modelId) {\n\t\t\tconst providerMatches = availableModels.filter(\n\t\t\t\t(model) =>\n\t\t\t\t\tmodel.provider.toLowerCase() === provider.toLowerCase() &&\n\t\t\t\t\tmodel.id.toLowerCase() === modelId.toLowerCase(),\n\t\t\t);\n\t\t\tif (providerMatches.length === 1) {\n\t\t\t\treturn providerMatches[0];\n\t\t\t}\n\t\t\tif (providerMatches.length > 1) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t}\n\t}\n\n\tconst idMatches = availableModels.filter((model) => model.id.toLowerCase() === normalizedReference);\n\treturn idMatches.length === 1 ? idMatches[0] : undefined;\n}\n\n/**\n * Try to match a pattern to a model from the available models list.\n * Returns the matched model or undefined if no match found.\n */\nfunction tryMatchModel(modelPattern: string, availableModels: Model<Api>[]): Model<Api> | undefined {\n\tconst exactMatch = findExactModelReferenceMatch(modelPattern, availableModels);\n\tif (exactMatch) {\n\t\treturn exactMatch;\n\t}\n\n\tconst matches = availableModels.filter(\n\t\t(m) =>\n\t\t\tm.id.toLowerCase().includes(modelPattern.toLowerCase()) ||\n\t\t\tm.name?.toLowerCase().includes(modelPattern.toLowerCase()),\n\t);\n\n\tif (matches.length === 0) {\n\t\treturn undefined;\n\t}\n\n\tconst aliases = matches.filter((m) => isAlias(m.id));\n\tconst datedVersions = matches.filter((m) => !isAlias(m.id));\n\n\tif (aliases.length > 0) {\n\t\taliases.sort((a, b) => b.id.localeCompare(a.id));\n\t\treturn aliases[0];\n\t}\n\n\tdatedVersions.sort((a, b) => b.id.localeCompare(a.id));\n\treturn datedVersions[0];\n}\n\nexport function buildFallbackModel(\n\tprovider: string,\n\tmodelId: string,\n\tavailableModels: Model<Api>[],\n): Model<Api> | undefined {\n\tconst providerModels = availableModels.filter((m) => m.provider === provider);\n\tif (providerModels.length === 0) return undefined;\n\n\tconst defaultId = defaultModelPerProvider[provider];\n\tconst baseModel = defaultId\n\t\t? (providerModels.find((m) => m.id === defaultId) ?? providerModels[0])\n\t\t: providerModels[0];\n\tconst fallbackContextWindow = baseModel.contextWindow;\n\n\treturn {\n\t\t...baseModel,\n\t\tid: modelId,\n\t\tname: modelId,\n\t\tcontextWindow: fallbackContextWindow,\n\t};\n}\n\n/**\n * Parse a pattern to extract model and thinking level.\n * Handles models with colons in their IDs (e.g., OpenRouter's :exacto suffix).\n *\n * Algorithm:\n * 1. Try to match full pattern as a model\n * 2. If found, return it with \"off\" thinking level\n * 3. If not found and has colons, split on last colon:\n * - If suffix is valid thinking level, use it and recurse on prefix\n * - If suffix is invalid, warn and recurse on prefix with \"off\"\n *\n * @internal Exported for testing\n */\nexport function parseModelPattern(\n\tpattern: string,\n\tavailableModels: Model<Api>[],\n\toptions?: { allowInvalidThinkingLevelFallback?: boolean },\n): ParsedModelResult {\n\tconst exactMatch = tryMatchModel(pattern, availableModels);\n\tif (exactMatch) {\n\t\treturn { model: exactMatch, thinkingLevel: undefined, warning: undefined };\n\t}\n\n\tconst lastColonIndex = pattern.lastIndexOf(\":\");\n\tif (lastColonIndex === -1) {\n\t\treturn { model: undefined, thinkingLevel: undefined, warning: undefined };\n\t}\n\n\tconst prefix = pattern.substring(0, lastColonIndex);\n\tconst suffix = pattern.substring(lastColonIndex + 1);\n\n\tif (isValidThinkingLevel(suffix)) {\n\t\tconst result = parseModelPattern(prefix, availableModels, options);\n\t\tif (result.model) {\n\t\t\treturn {\n\t\t\t\tmodel: result.model,\n\t\t\t\tthinkingLevel: result.warning ? undefined : (suffix as ThinkingLevel),\n\t\t\t\twarning: result.warning,\n\t\t\t};\n\t\t}\n\t\treturn result;\n\t}\n\n\tconst allowFallback = options?.allowInvalidThinkingLevelFallback ?? true;\n\tif (!allowFallback) {\n\t\treturn { model: undefined, thinkingLevel: undefined, warning: undefined };\n\t}\n\n\tconst result = parseModelPattern(prefix, availableModels, options);\n\tif (result.model) {\n\t\treturn {\n\t\t\tmodel: result.model,\n\t\t\tthinkingLevel: undefined,\n\t\t\twarning: `Invalid thinking level \"${suffix}\" in pattern \"${pattern}\". Using default instead.`,\n\t\t};\n\t}\n\treturn result;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"model-resolver-patterns.js","sourceRoot":"","sources":["../../src/core/model-resolver-patterns.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;A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AAM,SAAS,GAAG,SAAS;QAC1B,CAAC,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,SAAS,CAAC,IAAI,cAAc,CAAC,CAAC,CAAC,CAAC;QACvE,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;IACrB,MAAM,qBAAqB,GAAG,SAAS,CAAC,aAAa,CAAC;IAEtD,OAAO;QACN,GAAG,SAAS;QACZ,EAAE,EAAE,OAAO;QACX,IAAI,EAAE,OAAO;QACb,aAAa,EAAE,qBAAqB;KACpC,CAAC;AACH,CAAC","sourcesContent":["import type { Api, Model } from \"@bastani/pi-ai/compat\";\nimport type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport { isValidThinkingLevel } from \"../cli/args.ts\";\nimport { normalizeModelReference } from \"./azure-provider-compat.js\";\nimport { defaultModelPerProvider } from \"./model-resolver-defaults.ts\";\n\n/*\n * Model reference resolution. Candidates are collected before a provider is chosen, so catalog order\n * never decides the provider and an ambiguous match is reported instead of falling through to a\n * weaker one.\n */\n\nexport interface ModelReferenceRequest {\n\t/** Bare model id or `provider/id`, optionally followed by `:<thinking>`. */\n\ttext: string;\n\t/** Only consider models from this provider. */\n\tprovider?: string;\n\t/**\n\t * A trailing `:<suffix>` is only considered when the full text matches no model, since ids such as\n\t * OpenRouter's `qwen/qwen3-coder:exacto` contain colons.\n\t * - `none`: the suffix stays part of the id\n\t * - `strict`: a valid thinking level is parsed; any other suffix stays part of the id\n\t * - `lenient`: like `strict`, but an invalid suffix is dropped with a warning\n\t */\n\tthinkingSuffix: \"none\" | \"strict\" | \"lenient\";\n\t/** Match id and name substrings when no exact match exists. */\n\tfuzzy: boolean;\n}\n\nexport type ModelReferenceResult =\n\t| { status: \"resolved\"; model: Model<Api>; thinkingLevel?: ThinkingLevel; warning?: string }\n\t| {\n\t\t\tstatus: \"ambiguous\";\n\t\t\tcandidates: Model<Api>[];\n\t\t\tusableCount: number;\n\t\t\tthinkingLevel?: ThinkingLevel;\n\t\t\twarning?: string;\n\t }\n\t| {\n\t\t\tstatus: \"not-found\";\n\t\t\t/** Set when a provider is explicit or named by a `provider/` prefix, for building a custom model id. */\n\t\t\ttarget?: ModelReferenceTarget;\n\t };\n\nexport interface ModelReferenceTarget {\n\tprovider: string;\n\tproviderModels: [Model<Api>, ...Model<Api>[]];\n\t/** Text after the provider prefix as typed, including any `:<suffix>`. */\n\tmodelText: string;\n\t/** `modelText` without a valid thinking suffix (unless `thinkingSuffix` is `none`). */\n\tmodelId: string;\n\tthinkingLevel?: ThinkingLevel;\n}\n\ntype ResolvedOrAmbiguous = Exclude<ModelReferenceResult, { status: \"not-found\" }>;\n\nfunction splitThinkingSuffix(text: string): { base: string; thinkingLevel: ThinkingLevel } | undefined {\n\tconst colonIndex = text.lastIndexOf(\":\");\n\tconst suffix = text.substring(colonIndex + 1);\n\tif (colonIndex <= 0 || !isValidThinkingLevel(suffix)) return undefined;\n\treturn { base: text.substring(0, colonIndex), thinkingLevel: suffix };\n}\n\nfunction splitProviderPrefix(\n\ttext: string,\n\tmodels: readonly Model<Api>[],\n): { provider: string; modelText: string } | undefined {\n\tconst slashIndex = text.indexOf(\"/\");\n\tif (slashIndex === -1) return undefined;\n\tconst prefix = text.substring(0, slashIndex).trim().toLowerCase();\n\tconst modelText = text.substring(slashIndex + 1).trim();\n\tif (!prefix || !modelText) return undefined;\n\tconst provider = models.find((model) => model.provider.toLowerCase() === prefix)?.provider;\n\treturn provider ? { provider, modelText } : undefined;\n}\n\n/** Duplicate entries from one provider must not look like several providers. */\nfunction uniqueByReference(models: readonly Model<Api>[]): Model<Api>[] {\n\tconst seen = new Set<string>();\n\treturn models.filter((model) => {\n\t\tconst key = `${model.provider.toLowerCase()}/${model.id.toLowerCase()}`;\n\t\tif (seen.has(key)) return false;\n\t\tseen.add(key);\n\t\treturn true;\n\t});\n}\n\n/**\n * `usable` only breaks ties between providers, so a unique match resolves even without credentials\n * (`--api-key` first-time setup).\n */\nexport function resolveModelReference(\n\trequest: ModelReferenceRequest,\n\tmodels: readonly Model<Api>[],\n\tusable: (provider: string) => boolean,\n): ModelReferenceResult {\n\tconst text = normalizeModelReference(request.text.trim());\n\tif (!text) return { status: \"not-found\" };\n\tconst constraint = request.provider?.toLowerCase();\n\tconst pool = constraint ? models.filter((model) => model.provider.toLowerCase() === constraint) : models;\n\tconst result = resolveText(text, request, pool, usable);\n\tif (result.status !== \"not-found\") return result;\n\n\tconst split = splitProviderPrefix(text, pool);\n\tconst anchor = constraint ? pool[0] : pool.find((model) => model.provider === split?.provider);\n\tif (!anchor) return result;\n\tconst modelText = split?.modelText ?? text;\n\tconst suffix = request.thinkingSuffix === \"none\" ? undefined : splitThinkingSuffix(modelText);\n\treturn {\n\t\tstatus: \"not-found\",\n\t\ttarget: {\n\t\t\tprovider: anchor.provider,\n\t\t\tproviderModels: [anchor, ...pool.filter((model) => model.provider === anchor.provider && model !== anchor)],\n\t\t\tmodelText,\n\t\t\tmodelId: suffix?.base ?? modelText,\n\t\t\tthinkingLevel: suffix?.thinkingLevel,\n\t\t},\n\t};\n}\n\n/** Exact `provider/id` or bare id lookup without thinking suffixes or fuzzy matching. */\nexport function findExactModelReferenceMatch(\n\tmodelReference: string,\n\tmodels: readonly Model<Api>[],\n): Model<Api> | undefined {\n\tconst result = resolveModelReference(\n\t\t{ text: modelReference, thinkingSuffix: \"none\", fuzzy: false },\n\t\tmodels,\n\t\t() => true,\n\t);\n\treturn result.status === \"resolved\" ? result.model : undefined;\n}\n\nfunction resolveText(\n\ttext: string,\n\trequest: ModelReferenceRequest,\n\tpool: readonly Model<Api>[],\n\tusable: (provider: string) => boolean,\n): ModelReferenceResult {\n\tconst reference = selectReference(text, pool, request.fuzzy, usable);\n\tif (reference) return reference;\n\n\tif (request.fuzzy) {\n\t\tconst fuzzy = selectFuzzy(fuzzyMatches(text, pool), usable);\n\t\tif (fuzzy) return fuzzy;\n\t}\n\n\tif (request.thinkingSuffix === \"none\") return { status: \"not-found\" };\n\tconst thinking = splitThinkingSuffix(text);\n\tif (thinking) {\n\t\tconst inner = resolveText(thinking.base, request, pool, usable);\n\t\tif (inner.status === \"not-found\") return inner;\n\t\t// An inner warning means an invalid inner suffix, which discards the thinking level\n\t\treturn { ...inner, thinkingLevel: inner.warning ? undefined : thinking.thinkingLevel };\n\t}\n\t// Keep an invalid suffix as part of the id and fail, rather than resolve a different model\n\tif (request.thinkingSuffix === \"strict\") return { status: \"not-found\" };\n\tconst colonIndex = text.lastIndexOf(\":\");\n\tif (colonIndex <= 0) return { status: \"not-found\" };\n\n\tconst suffix = text.substring(colonIndex + 1);\n\tconst inner = resolveText(text.substring(0, colonIndex), request, pool, usable);\n\tif (inner.status === \"not-found\") return inner;\n\treturn {\n\t\t...inner,\n\t\tthinkingLevel: undefined,\n\t\twarning: `Invalid thinking level \"${suffix}\" in pattern \"${text}\". Using default instead.`,\n\t};\n}\n\n/**\n * `provider/rest` is only a hint: the whole text may also be a model id on another provider, such as\n * gateway id `zai/glm-5` or commandcode id `xiaomi/mimo-v2.5-pro`. The named provider wins when usable,\n * since that is what the syntax usually means; otherwise a sole usable raw match wins, since the named\n * provider could not serve the request. An unusable named match is still preferred over unusable raw\n * matches, so `--api-key` can set up the named provider.\n */\nfunction selectReference(\n\ttext: string,\n\tpool: readonly Model<Api>[],\n\tfuzzy: boolean,\n\tusable: (provider: string) => boolean,\n): ResolvedOrAmbiguous | undefined {\n\tconst lowerText = text.toLowerCase();\n\tconst raw = uniqueByReference(pool.filter((model) => model.id.toLowerCase() === lowerText));\n\tconst split = splitProviderPrefix(text, pool);\n\tlet named: Model<Api> | undefined;\n\tif (split) {\n\t\tconst providerModels = pool.filter((model) => model.provider === split.provider);\n\t\tconst lowerModelText = split.modelText.toLowerCase();\n\t\t// The provider's own literal id (OpenRouter's `openrouter/free`) beats its fuzzy matches\n\t\tnamed =\n\t\t\tproviderModels.find((model) => model.id.toLowerCase() === lowerModelText) ??\n\t\t\traw.find((model) => model.provider === split.provider) ??\n\t\t\t(fuzzy ? bestFuzzyMatch(fuzzyMatches(split.modelText, providerModels)) : undefined);\n\t}\n\n\tconst others = raw.filter((model) => model !== named);\n\tconst candidates = named ? [named, ...others] : others;\n\tif (candidates.length === 0) return undefined;\n\tif (new Set(candidates.map((model) => model.provider)).size === 1) {\n\t\treturn { status: \"resolved\", model: candidates[0] };\n\t}\n\tif (named && usable(named.provider)) return { status: \"resolved\", model: named };\n\tconst usableOthers = others.filter((model) => usable(model.provider));\n\tif (usableOthers.length === 1) return { status: \"resolved\", model: usableOthers[0] };\n\tif (usableOthers.length === 0 && named) return { status: \"resolved\", model: named };\n\treturn { status: \"ambiguous\", candidates, usableCount: usableOthers.length };\n}\n\nfunction fuzzyMatches(text: string, models: readonly Model<Api>[]): Model<Api>[] {\n\tconst lowerText = text.toLowerCase();\n\treturn models.filter(\n\t\t(model) => model.id.toLowerCase().includes(lowerText) || model.name?.toLowerCase().includes(lowerText),\n\t);\n}\n\nfunction selectFuzzy(matches: Model<Api>[], usable: (provider: string) => boolean): ResolvedOrAmbiguous | undefined {\n\tif (matches.length === 0) return undefined;\n\tconst multipleProviders = new Set(matches.map((model) => model.provider)).size > 1;\n\tconst usableMatches = multipleProviders ? matches.filter((model) => usable(model.provider)) : [];\n\tconst pool = usableMatches.length > 0 ? usableMatches : matches;\n\tconst best = bestFuzzyMatch(pool);\n\tif (!best) return undefined;\n\t// The same id on several providers would otherwise be decided by catalog order\n\tconst tied = uniqueByReference(pool.filter((model) => model.id === best.id));\n\tif (new Set(tied.map((model) => model.provider)).size === 1) return { status: \"resolved\", model: best };\n\treturn {\n\t\tstatus: \"ambiguous\",\n\t\tcandidates: tied,\n\t\tusableCount: usableMatches.length > 0 ? tied.length : 0,\n\t};\n}\n\n/** Prefer aliases (`claude-sonnet-4-5`) over dated versions (`claude-sonnet-4-5-20250929`), then the latest. */\nfunction bestFuzzyMatch(matches: readonly Model<Api>[]): Model<Api> | undefined {\n\tconst aliases = matches.filter((model) => isAlias(model.id));\n\treturn [...(aliases.length > 0 ? aliases : matches)].sort((a, b) => b.id.localeCompare(a.id))[0];\n}\n\nfunction isAlias(id: string): boolean {\n\treturn id.endsWith(\"-latest\") || !/-\\d{8}$/.test(id);\n}\n\nexport function buildFallbackModel(\n\tprovider: string,\n\tmodelId: string,\n\tavailableModels: readonly Model<Api>[],\n): Model<Api> | undefined {\n\tconst providerModels = availableModels.filter((m) => m.provider === provider);\n\tif (providerModels.length === 0) return undefined;\n\n\tconst defaultId = defaultModelPerProvider[provider];\n\tconst baseModel = defaultId\n\t\t? (providerModels.find((m) => m.id === defaultId) ?? providerModels[0])\n\t\t: providerModels[0];\n\tconst fallbackContextWindow = baseModel.contextWindow;\n\n\treturn {\n\t\t...baseModel,\n\t\tid: modelId,\n\t\tname: modelId,\n\t\tcontextWindow: fallbackContextWindow,\n\t};\n}\n"]}
|
|
@@ -3,7 +3,7 @@ import type { ScopedModel } from "./model-resolver-types.ts";
|
|
|
3
3
|
import type { ModelRuntime } from "./model-runtime.js";
|
|
4
4
|
export interface ModelScopeDiagnostic {
|
|
5
5
|
type: "warning";
|
|
6
|
-
code: "no-match" | "invalid-thinking-level";
|
|
6
|
+
code: "no-match" | "invalid-thinking-level" | "ambiguous";
|
|
7
7
|
message: string;
|
|
8
8
|
pattern: string;
|
|
9
9
|
}
|
|
@@ -12,15 +12,12 @@ export interface ResolveModelScopeResult {
|
|
|
12
12
|
diagnostics: ModelScopeDiagnostic[];
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
|
-
* Resolve
|
|
16
|
-
* Format: "pattern:level" where :level is optional
|
|
17
|
-
* For each pattern, finds all matching models and picks the best version:
|
|
18
|
-
* 1. Prefer alias (e.g., claude-sonnet-4-5) over dated versions (claude-sonnet-4-5-20250929)
|
|
19
|
-
* 2. If no alias, pick the latest dated version
|
|
15
|
+
* Resolve scope patterns (`--models`, `enabledModels`) to models with optional thinking levels.
|
|
20
16
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
17
|
+
* A complete literal reference is tried first, then glob patterns, then fuzzy matching with an
|
|
18
|
+
* optional `:<thinking>` suffix. Every model in `models` is usable, so credentials cannot choose
|
|
19
|
+
* between providers offering the same id. All of them are added, with a warning so the user can pick
|
|
20
|
+
* one with `provider/id`.
|
|
24
21
|
*/
|
|
25
22
|
export declare function resolveModelScopeFromModels(patterns: string[], models: readonly Model<Api>[]): ResolveModelScopeResult;
|
|
26
23
|
export declare function resolveModelScopeWithDiagnostics(patterns: string[], modelRuntime: ModelRuntime): Promise<ResolveModelScopeResult>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-resolver-scope.d.ts","sourceRoot":"","sources":["../../src/core/model-resolver-scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK,KAAK,EAAkB,MAAM,uBAAuB,CAAC;AAO7E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,MAAM,WAAW,oBAAoB;IACpC,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,UAAU,GAAG,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"model-resolver-scope.d.ts","sourceRoot":"","sources":["../../src/core/model-resolver-scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK,KAAK,EAAkB,MAAM,uBAAuB,CAAC;AAO7E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,MAAM,WAAW,oBAAoB;IACpC,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,UAAU,GAAG,wBAAwB,GAAG,WAAW,CAAC;IAC1D,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,uBAAuB;IACvC,YAAY,EAAE,WAAW,EAAE,CAAC;IAC5B,WAAW,EAAE,oBAAoB,EAAE,CAAC;CACpC;AAwBD;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CAC1C,QAAQ,EAAE,MAAM,EAAE,EAClB,MAAM,EAAE,SAAS,KAAK,CAAC,GAAG,CAAC,EAAE,GAC3B,uBAAuB,CAoEzB;AAED,wBAAsB,gCAAgC,CACrD,QAAQ,EAAE,MAAM,EAAE,EAClB,YAAY,EAAE,YAAY,GACxB,OAAO,CAAC,uBAAuB,CAAC,CAElC;AAED,wBAAsB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAM9G"}
|
|
@@ -3,7 +3,7 @@ import chalk from "chalk";
|
|
|
3
3
|
import { minimatch } from "minimatch";
|
|
4
4
|
import { isValidThinkingLevel } from "../cli/args.js";
|
|
5
5
|
import { normalizeModelReference } from "./azure-provider-compat.js";
|
|
6
|
-
import {
|
|
6
|
+
import { resolveModelReference } from "./model-resolver-patterns.js";
|
|
7
7
|
function hasGlobCharacters(pattern) {
|
|
8
8
|
return pattern.includes("*") || pattern.includes("?") || pattern.includes("[");
|
|
9
9
|
}
|
|
@@ -18,75 +18,73 @@ function parseGlobThinkingLevel(pattern) {
|
|
|
18
18
|
}
|
|
19
19
|
return { globPattern: pattern.substring(0, colonIdx), thinkingLevel: suffix };
|
|
20
20
|
}
|
|
21
|
+
function resolveExactReference(text, models) {
|
|
22
|
+
return resolveModelReference({ text, thinkingSuffix: "none", fuzzy: false }, models, () => true);
|
|
23
|
+
}
|
|
21
24
|
/**
|
|
22
|
-
* Resolve
|
|
23
|
-
* Format: "pattern:level" where :level is optional
|
|
24
|
-
* For each pattern, finds all matching models and picks the best version:
|
|
25
|
-
* 1. Prefer alias (e.g., claude-sonnet-4-5) over dated versions (claude-sonnet-4-5-20250929)
|
|
26
|
-
* 2. If no alias, pick the latest dated version
|
|
25
|
+
* Resolve scope patterns (`--models`, `enabledModels`) to models with optional thinking levels.
|
|
27
26
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
27
|
+
* A complete literal reference is tried first, then glob patterns, then fuzzy matching with an
|
|
28
|
+
* optional `:<thinking>` suffix. Every model in `models` is usable, so credentials cannot choose
|
|
29
|
+
* between providers offering the same id. All of them are added, with a warning so the user can pick
|
|
30
|
+
* one with `provider/id`.
|
|
31
31
|
*/
|
|
32
32
|
export function resolveModelScopeFromModels(patterns, models) {
|
|
33
|
-
const availableModels = [...models];
|
|
34
33
|
const scopedModels = [];
|
|
35
34
|
const diagnostics = [];
|
|
35
|
+
const add = (model, thinkingLevel) => {
|
|
36
|
+
if (!scopedModels.some((scoped) => modelsAreEqual(scoped.model, model))) {
|
|
37
|
+
scopedModels.push({ model, thinkingLevel });
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const noMatch = (pattern) => diagnostics.push({ type: "warning", code: "no-match", message: `No models match pattern "${pattern}"`, pattern });
|
|
41
|
+
const ambiguous = (pattern, candidates) => {
|
|
42
|
+
const providers = [...new Set(candidates.map((model) => model.provider))].sort((a, b) => a.localeCompare(b));
|
|
43
|
+
diagnostics.push({
|
|
44
|
+
type: "warning",
|
|
45
|
+
code: "ambiguous",
|
|
46
|
+
message: `Pattern "${pattern}" matches several providers: ${providers.join(", ")}. Use provider/id to choose one.`,
|
|
47
|
+
pattern,
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
const addResult = (pattern, result, thinkingLevel) => {
|
|
51
|
+
if (result.status === "not-found")
|
|
52
|
+
return false;
|
|
53
|
+
if (result.status === "ambiguous")
|
|
54
|
+
ambiguous(pattern, result.candidates);
|
|
55
|
+
const matches = result.status === "resolved" ? [result.model] : result.candidates;
|
|
56
|
+
for (const model of matches)
|
|
57
|
+
add(model, thinkingLevel);
|
|
58
|
+
return true;
|
|
59
|
+
};
|
|
36
60
|
for (const rawPattern of patterns) {
|
|
37
61
|
const pattern = normalizeModelReference(rawPattern);
|
|
38
|
-
|
|
39
|
-
if (completeExactMatch) {
|
|
40
|
-
if (!scopedModels.find((scoped) => modelsAreEqual(scoped.model, completeExactMatch))) {
|
|
41
|
-
scopedModels.push({ model: completeExactMatch, thinkingLevel: undefined });
|
|
42
|
-
}
|
|
62
|
+
if (addResult(pattern, resolveExactReference(pattern, models), undefined))
|
|
43
63
|
continue;
|
|
44
|
-
}
|
|
45
64
|
if (hasGlobCharacters(pattern)) {
|
|
46
65
|
const { globPattern, thinkingLevel } = parseGlobThinkingLevel(pattern);
|
|
47
|
-
|
|
48
|
-
if (
|
|
49
|
-
if (!scopedModels.find((scoped) => modelsAreEqual(scoped.model, exactMatch))) {
|
|
50
|
-
scopedModels.push({ model: exactMatch, thinkingLevel });
|
|
51
|
-
}
|
|
66
|
+
// Ids such as `bracketed-model[1m]` are not globs
|
|
67
|
+
if (addResult(pattern, resolveExactReference(globPattern, models), thinkingLevel))
|
|
52
68
|
continue;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
code: "no-match",
|
|
62
|
-
message: `No models match pattern "${pattern}"`,
|
|
63
|
-
pattern,
|
|
64
|
-
});
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
for (const model of matchingModels) {
|
|
68
|
-
if (!scopedModels.find((scoped) => modelsAreEqual(scoped.model, model))) {
|
|
69
|
-
scopedModels.push({ model, thinkingLevel });
|
|
70
|
-
}
|
|
71
|
-
}
|
|
69
|
+
// Match against "provider/modelId" format OR just model ID
|
|
70
|
+
// This allows "*sonnet*" to match without requiring "anthropic/*sonnet*"
|
|
71
|
+
const matches = models.filter((model) => minimatch(`${model.provider}/${model.id}`, globPattern, { nocase: true }) ||
|
|
72
|
+
minimatch(model.id, globPattern, { nocase: true }));
|
|
73
|
+
if (matches.length === 0)
|
|
74
|
+
noMatch(pattern);
|
|
75
|
+
for (const model of matches)
|
|
76
|
+
add(model, thinkingLevel);
|
|
72
77
|
continue;
|
|
73
78
|
}
|
|
74
|
-
const {
|
|
75
|
-
if (
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
if (!model) {
|
|
79
|
-
diagnostics.push({
|
|
80
|
-
type: "warning",
|
|
81
|
-
code: "no-match",
|
|
82
|
-
message: `No models match pattern "${pattern}"`,
|
|
83
|
-
pattern,
|
|
84
|
-
});
|
|
79
|
+
const result = resolveModelReference({ text: pattern, thinkingSuffix: "lenient", fuzzy: true }, models, () => true);
|
|
80
|
+
if (result.status === "not-found") {
|
|
81
|
+
noMatch(pattern);
|
|
85
82
|
continue;
|
|
86
83
|
}
|
|
87
|
-
if (
|
|
88
|
-
|
|
84
|
+
if (result.warning) {
|
|
85
|
+
diagnostics.push({ type: "warning", code: "invalid-thinking-level", message: result.warning, pattern });
|
|
89
86
|
}
|
|
87
|
+
addResult(pattern, result, result.thinkingLevel);
|
|
90
88
|
}
|
|
91
89
|
return { scopedModels, diagnostics };
|
|
92
90
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-resolver-scope.js","sourceRoot":"","sources":["../../src/core/model-resolver-scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE7E,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,EAAE,4BAA4B,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAgB/F,SAAS,iBAAiB,CAAC,OAAe;IACzC,OAAO,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,OAA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AAC,QAAkB,EAAE,YAA0B;IACrF,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,GAAG,MAAM,gCAAgC,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;IACrG,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;QACtC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,YAAY,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IAC9D,CAAC;IACD,OAAO,YAAY,CAAC;AACrB,CAAC","sourcesContent":["import { type Api, type Model, modelsAreEqual } from \"@bastani/pi-ai/compat\";\nimport type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport chalk from \"chalk\";\nimport { minimatch } from \"minimatch\";\nimport { isValidThinkingLevel } from \"../cli/args.ts\";\nimport { normalizeModelReference } from \"./azure-provider-compat.js\";\nimport { findExactModelReferenceMatch, parseModelPattern } from \"./model-resolver-patterns.ts\";\nimport type { ScopedModel } from \"./model-resolver-types.ts\";\nimport type { ModelRuntime } from \"./model-runtime.js\";\n\nexport interface ModelScopeDiagnostic {\n\ttype: \"warning\";\n\tcode: \"no-match\" | \"invalid-thinking-level\";\n\tmessage: string;\n\tpattern: string;\n}\n\nexport interface ResolveModelScopeResult {\n\tscopedModels: ScopedModel[];\n\tdiagnostics: ModelScopeDiagnostic[];\n}\n\nfunction hasGlobCharacters(pattern: string): boolean {\n\treturn pattern.includes(\"*\") || pattern.includes(\"?\") || pattern.includes(\"[\");\n}\n\nfunction parseGlobThinkingLevel(pattern: string): { globPattern: string; thinkingLevel?: ThinkingLevel } {\n\tconst colonIdx = pattern.lastIndexOf(\":\");\n\tif (colonIdx === -1) {\n\t\treturn { globPattern: pattern };\n\t}\n\n\tconst suffix = pattern.substring(colonIdx + 1);\n\tif (!isValidThinkingLevel(suffix)) {\n\t\treturn { globPattern: pattern };\n\t}\n\n\treturn { globPattern: pattern.substring(0, colonIdx), thinkingLevel: suffix };\n}\n\n/**\n * Resolve model patterns to actual Model objects with optional thinking levels\n * Format: \"pattern:level\" where :level is optional\n * For each pattern, finds all matching models and picks the best version:\n * 1. Prefer alias (e.g., claude-sonnet-4-5) over dated versions (claude-sonnet-4-5-20250929)\n * 2. If no alias, pick the latest dated version\n *\n * Supports models with colons in their IDs (e.g., OpenRouter's model:exacto).\n * The algorithm tries to match the full pattern first, then progressively\n * strips colon-suffixes to find a match.\n */\nexport function resolveModelScopeFromModels(\n\tpatterns: string[],\n\tmodels: readonly Model<Api>[],\n): ResolveModelScopeResult {\n\tconst availableModels = [...models];\n\tconst scopedModels: ScopedModel[] = [];\n\tconst diagnostics: ModelScopeDiagnostic[] = [];\n\tfor (const rawPattern of patterns) {\n\t\tconst pattern = normalizeModelReference(rawPattern);\n\t\tconst completeExactMatch = findExactModelReferenceMatch(pattern, availableModels);\n\t\tif (completeExactMatch) {\n\t\t\tif (!scopedModels.find((scoped) => modelsAreEqual(scoped.model, completeExactMatch))) {\n\t\t\t\tscopedModels.push({ model: completeExactMatch, thinkingLevel: undefined });\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (hasGlobCharacters(pattern)) {\n\t\t\tconst { globPattern, thinkingLevel } = parseGlobThinkingLevel(pattern);\n\t\t\tconst exactMatch = findExactModelReferenceMatch(globPattern, availableModels);\n\t\t\tif (exactMatch) {\n\t\t\t\tif (!scopedModels.find((scoped) => modelsAreEqual(scoped.model, exactMatch))) {\n\t\t\t\t\tscopedModels.push({ model: exactMatch, thinkingLevel });\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst matchingModels = availableModels.filter((model) => {\n\t\t\t\tconst fullId = `${model.provider}/${model.id}`;\n\t\t\t\treturn (\n\t\t\t\t\tminimatch(fullId, globPattern, { nocase: true }) || minimatch(model.id, globPattern, { nocase: true })\n\t\t\t\t);\n\t\t\t});\n\n\t\t\tif (matchingModels.length === 0) {\n\t\t\t\tdiagnostics.push({\n\t\t\t\t\ttype: \"warning\",\n\t\t\t\t\tcode: \"no-match\",\n\t\t\t\t\tmessage: `No models match pattern \"${pattern}\"`,\n\t\t\t\t\tpattern,\n\t\t\t\t});\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tfor (const model of matchingModels) {\n\t\t\t\tif (!scopedModels.find((scoped) => modelsAreEqual(scoped.model, model))) {\n\t\t\t\t\tscopedModels.push({ model, thinkingLevel });\n\t\t\t\t}\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst { model, thinkingLevel, warning } = parseModelPattern(pattern, availableModels);\n\n\t\tif (warning) {\n\t\t\tdiagnostics.push({ type: \"warning\", code: \"invalid-thinking-level\", message: warning, pattern });\n\t\t}\n\n\t\tif (!model) {\n\t\t\tdiagnostics.push({\n\t\t\t\ttype: \"warning\",\n\t\t\t\tcode: \"no-match\",\n\t\t\t\tmessage: `No models match pattern \"${pattern}\"`,\n\t\t\t\tpattern,\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (!scopedModels.find((scoped) => modelsAreEqual(scoped.model, model))) {\n\t\t\tscopedModels.push({ model, thinkingLevel });\n\t\t}\n\t}\n\n\treturn { scopedModels, diagnostics };\n}\n\nexport async function resolveModelScopeWithDiagnostics(\n\tpatterns: string[],\n\tmodelRuntime: ModelRuntime,\n): Promise<ResolveModelScopeResult> {\n\treturn resolveModelScopeFromModels(patterns, modelRuntime.getAvailableSnapshot());\n}\n\nexport async function resolveModelScope(patterns: string[], modelRuntime: ModelRuntime): Promise<ScopedModel[]> {\n\tconst { scopedModels, diagnostics } = await resolveModelScopeWithDiagnostics(patterns, modelRuntime);\n\tfor (const diagnostic of diagnostics) {\n\t\tconsole.warn(chalk.yellow(`Warning: ${diagnostic.message}`));\n\t}\n\treturn scopedModels;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"model-resolver-scope.js","sourceRoot":"","sources":["../../src/core/model-resolver-scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,cAAc,EAAE,MAAM,uBAAuB,CAAC;A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;IAC9D,CAAC;IACD,OAAO,YAAY,CAAC;AACrB,CAAC","sourcesContent":["import { type Api, type Model, modelsAreEqual } from \"@bastani/pi-ai/compat\";\nimport type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport chalk from \"chalk\";\nimport { minimatch } from \"minimatch\";\nimport { isValidThinkingLevel } from \"../cli/args.ts\";\nimport { normalizeModelReference } from \"./azure-provider-compat.js\";\nimport { type ModelReferenceResult, resolveModelReference } from \"./model-resolver-patterns.ts\";\nimport type { ScopedModel } from \"./model-resolver-types.ts\";\nimport type { ModelRuntime } from \"./model-runtime.js\";\n\nexport interface ModelScopeDiagnostic {\n\ttype: \"warning\";\n\tcode: \"no-match\" | \"invalid-thinking-level\" | \"ambiguous\";\n\tmessage: string;\n\tpattern: string;\n}\n\nexport interface ResolveModelScopeResult {\n\tscopedModels: ScopedModel[];\n\tdiagnostics: ModelScopeDiagnostic[];\n}\n\nfunction hasGlobCharacters(pattern: string): boolean {\n\treturn pattern.includes(\"*\") || pattern.includes(\"?\") || pattern.includes(\"[\");\n}\n\nfunction parseGlobThinkingLevel(pattern: string): { globPattern: string; thinkingLevel?: ThinkingLevel } {\n\tconst colonIdx = pattern.lastIndexOf(\":\");\n\tif (colonIdx === -1) {\n\t\treturn { globPattern: pattern };\n\t}\n\n\tconst suffix = pattern.substring(colonIdx + 1);\n\tif (!isValidThinkingLevel(suffix)) {\n\t\treturn { globPattern: pattern };\n\t}\n\n\treturn { globPattern: pattern.substring(0, colonIdx), thinkingLevel: suffix };\n}\n\nfunction resolveExactReference(text: string, models: readonly Model<Api>[]): ModelReferenceResult {\n\treturn resolveModelReference({ text, thinkingSuffix: \"none\", fuzzy: false }, models, () => true);\n}\n\n/**\n * Resolve scope patterns (`--models`, `enabledModels`) to models with optional thinking levels.\n *\n * A complete literal reference is tried first, then glob patterns, then fuzzy matching with an\n * optional `:<thinking>` suffix. Every model in `models` is usable, so credentials cannot choose\n * between providers offering the same id. All of them are added, with a warning so the user can pick\n * one with `provider/id`.\n */\nexport function resolveModelScopeFromModels(\n\tpatterns: string[],\n\tmodels: readonly Model<Api>[],\n): ResolveModelScopeResult {\n\tconst scopedModels: ScopedModel[] = [];\n\tconst diagnostics: ModelScopeDiagnostic[] = [];\n\tconst add = (model: Model<Api>, thinkingLevel: ThinkingLevel | undefined) => {\n\t\tif (!scopedModels.some((scoped) => modelsAreEqual(scoped.model, model))) {\n\t\t\tscopedModels.push({ model, thinkingLevel });\n\t\t}\n\t};\n\tconst noMatch = (pattern: string) =>\n\t\tdiagnostics.push({ type: \"warning\", code: \"no-match\", message: `No models match pattern \"${pattern}\"`, pattern });\n\tconst ambiguous = (pattern: string, candidates: readonly Model<Api>[]) => {\n\t\tconst providers = [...new Set(candidates.map((model) => model.provider))].sort((a, b) => a.localeCompare(b));\n\t\tdiagnostics.push({\n\t\t\ttype: \"warning\",\n\t\t\tcode: \"ambiguous\",\n\t\t\tmessage: `Pattern \"${pattern}\" matches several providers: ${providers.join(\", \")}. Use provider/id to choose one.`,\n\t\t\tpattern,\n\t\t});\n\t};\n\tconst addResult = (\n\t\tpattern: string,\n\t\tresult: ModelReferenceResult,\n\t\tthinkingLevel: ThinkingLevel | undefined,\n\t): boolean => {\n\t\tif (result.status === \"not-found\") return false;\n\t\tif (result.status === \"ambiguous\") ambiguous(pattern, result.candidates);\n\t\tconst matches = result.status === \"resolved\" ? [result.model] : result.candidates;\n\t\tfor (const model of matches) add(model, thinkingLevel);\n\t\treturn true;\n\t};\n\n\tfor (const rawPattern of patterns) {\n\t\tconst pattern = normalizeModelReference(rawPattern);\n\t\tif (addResult(pattern, resolveExactReference(pattern, models), undefined)) continue;\n\n\t\tif (hasGlobCharacters(pattern)) {\n\t\t\tconst { globPattern, thinkingLevel } = parseGlobThinkingLevel(pattern);\n\t\t\t// Ids such as `bracketed-model[1m]` are not globs\n\t\t\tif (addResult(pattern, resolveExactReference(globPattern, models), thinkingLevel)) continue;\n\n\t\t\t// Match against \"provider/modelId\" format OR just model ID\n\t\t\t// This allows \"*sonnet*\" to match without requiring \"anthropic/*sonnet*\"\n\t\t\tconst matches = models.filter(\n\t\t\t\t(model) =>\n\t\t\t\t\tminimatch(`${model.provider}/${model.id}`, globPattern, { nocase: true }) ||\n\t\t\t\t\tminimatch(model.id, globPattern, { nocase: true }),\n\t\t\t);\n\t\t\tif (matches.length === 0) noMatch(pattern);\n\t\t\tfor (const model of matches) add(model, thinkingLevel);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst result = resolveModelReference(\n\t\t\t{ text: pattern, thinkingSuffix: \"lenient\", fuzzy: true },\n\t\t\tmodels,\n\t\t\t() => true,\n\t\t);\n\t\tif (result.status === \"not-found\") {\n\t\t\tnoMatch(pattern);\n\t\t\tcontinue;\n\t\t}\n\t\tif (result.warning) {\n\t\t\tdiagnostics.push({ type: \"warning\", code: \"invalid-thinking-level\", message: result.warning, pattern });\n\t\t}\n\t\taddResult(pattern, result, result.thinkingLevel);\n\t}\n\n\treturn { scopedModels, diagnostics };\n}\n\nexport async function resolveModelScopeWithDiagnostics(\n\tpatterns: string[],\n\tmodelRuntime: ModelRuntime,\n): Promise<ResolveModelScopeResult> {\n\treturn resolveModelScopeFromModels(patterns, modelRuntime.getAvailableSnapshot());\n}\n\nexport async function resolveModelScope(patterns: string[], modelRuntime: ModelRuntime): Promise<ScopedModel[]> {\n\tconst { scopedModels, diagnostics } = await resolveModelScopeWithDiagnostics(patterns, modelRuntime);\n\tfor (const diagnostic of diagnostics) {\n\t\tconsole.warn(chalk.yellow(`Warning: ${diagnostic.message}`));\n\t}\n\treturn scopedModels;\n}\n"]}
|
|
@@ -5,12 +5,6 @@ export interface ScopedModel {
|
|
|
5
5
|
/** Thinking level if explicitly specified in pattern (e.g., "model:high"), undefined otherwise */
|
|
6
6
|
thinkingLevel?: ThinkingLevel;
|
|
7
7
|
}
|
|
8
|
-
export interface ParsedModelResult {
|
|
9
|
-
model: Model<Api> | undefined;
|
|
10
|
-
/** Thinking level if explicitly specified in pattern, undefined otherwise */
|
|
11
|
-
thinkingLevel?: ThinkingLevel;
|
|
12
|
-
warning: string | undefined;
|
|
13
|
-
}
|
|
14
8
|
export interface ResolveCliModelResult {
|
|
15
9
|
model: Model<Api> | undefined;
|
|
16
10
|
thinkingLevel?: ThinkingLevel;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-resolver-types.d.ts","sourceRoot":"","sources":["../../src/core/model-resolver-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAEnE,MAAM,WAAW,WAAW;IAC3B,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IAClB,kGAAkG;IAClG,aAAa,CAAC,EAAE,aAAa,CAAC;CAC9B;AAED,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"model-resolver-types.d.ts","sourceRoot":"","sources":["../../src/core/model-resolver-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAEnE,MAAM,WAAW,WAAW;IAC3B,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IAClB,kGAAkG;IAClG,aAAa,CAAC,EAAE,aAAa,CAAC;CAC9B;AAED,MAAM,WAAW,qBAAqB;IACrC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;IAC9B,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B;;;OAGG;IACH,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1B;AAED,MAAM,MAAM,mBAAmB,GAAG,iBAAiB,GAAG,iCAAiC,GAAG,qBAAqB,CAAC;AAEhH,MAAM,WAAW,kBAAkB;IAClC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;IAC9B,aAAa,EAAE,aAAa,CAAC;IAC7B,eAAe,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,cAAc,CAAC,EAAE,mBAAmB,CAAC;CACrC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-resolver-types.js","sourceRoot":"","sources":["../../src/core/model-resolver-types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Api, Model } from \"@bastani/pi-ai/compat\";\nimport type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\n\nexport interface ScopedModel {\n\tmodel: Model<Api>;\n\t/** Thinking level if explicitly specified in pattern (e.g., \"model:high\"), undefined otherwise */\n\tthinkingLevel?: ThinkingLevel;\n}\n\nexport interface
|
|
1
|
+
{"version":3,"file":"model-resolver-types.js","sourceRoot":"","sources":["../../src/core/model-resolver-types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Api, Model } from \"@bastani/pi-ai/compat\";\nimport type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\n\nexport interface ScopedModel {\n\tmodel: Model<Api>;\n\t/** Thinking level if explicitly specified in pattern (e.g., \"model:high\"), undefined otherwise */\n\tthinkingLevel?: ThinkingLevel;\n}\n\nexport interface ResolveCliModelResult {\n\tmodel: Model<Api> | undefined;\n\tthinkingLevel?: ThinkingLevel;\n\twarning: string | undefined;\n\t/**\n\t * Error message suitable for CLI display.\n\t * When set, model will be undefined.\n\t */\n\terror: string | undefined;\n}\n\nexport type ModelFallbackReason = \"session-restore\" | \"configured-provider-unsupported\" | \"no-models-available\";\n\nexport interface InitialModelResult {\n\tmodel: Model<Api> | undefined;\n\tthinkingLevel: ThinkingLevel;\n\tfallbackMessage: string | undefined;\n\tfallbackReason?: ModelFallbackReason;\n}\n"]}
|