@f5-sales-demo/xcsh 21.9.3 → 21.10.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.
- package/package.json +8 -8
- package/src/cli/plugin-cli.ts +31 -17
- package/src/config/settings-schema.ts +1 -1
- package/src/extensibility/plugins/marketplace/index.ts +1 -0
- package/src/extensibility/plugins/marketplace/manager.ts +87 -15
- package/src/extensibility/plugins/marketplace/refresh.ts +7 -0
- package/src/internal-urls/build-info.generated.ts +8 -8
- package/src/internal-urls/docs-index.generated.ts +2 -1
- package/src/modes/components/login-dialog.ts +2 -2
- package/src/modes/components/model-selector.ts +2 -0
- package/src/modes/components/plugins/plugin-dashboard.ts +23 -25
- package/src/modes/components/plugins/state-manager.ts +13 -1
- package/src/modes/components/plugins/types.ts +1 -0
- package/src/modes/controllers/login-model.ts +29 -11
- package/src/modes/controllers/selector-controller.ts +41 -5
- package/src/routing/presets.ts +2 -10
- package/src/routing/resolver.ts +26 -28
- package/src/routing/subscription-profiles.ts +41 -3
- package/src/session/agent-session.ts +1 -1
- package/src/slash-commands/builtin-registry.ts +35 -17
|
@@ -109,6 +109,7 @@ function getModelPublisher(model: Model): string {
|
|
|
109
109
|
|
|
110
110
|
function getModelFamily(model: Model): string {
|
|
111
111
|
if (model.family) return model.family;
|
|
112
|
+
if (model.provider === "anthropic" && /^claude-(?:haiku|sonnet|opus)-/i.test(model.id)) return "Claude";
|
|
112
113
|
return (
|
|
113
114
|
model.name.match(/^(?:Gemini\s+\d+(?:\.\d+)?|GPT-\d+(?:\.\d+)?|Claude\s+\S+(?:\s+\d+(?:\.\d+)?)?)/i)?.[0] ??
|
|
114
115
|
model.name
|
|
@@ -189,6 +190,7 @@ export function filterCurrentBrowserModels(models: readonly Model[]): Model[] {
|
|
|
189
190
|
}
|
|
190
191
|
|
|
191
192
|
export function getProviderDisplayName(provider: string): string {
|
|
193
|
+
if (provider === "anthropic") return "Anthropic / Claude";
|
|
192
194
|
if (provider === "openai-codex") return "ChatGPT Subscription";
|
|
193
195
|
if (provider === "openai") return "OpenAI API Key";
|
|
194
196
|
if (provider === "google-vertex") return "Google Vertex";
|
|
@@ -16,6 +16,7 @@ import { invalidate as invalidateFsCache } from "../../../capability/fs";
|
|
|
16
16
|
import { clearXcshPluginRootsCache, resolveActiveProjectRegistryPath } from "../../../discovery/helpers";
|
|
17
17
|
import { PluginManager } from "../../../extensibility/plugins";
|
|
18
18
|
import {
|
|
19
|
+
formatMarketplaceRefreshWarning,
|
|
19
20
|
getInstalledPluginsRegistryPath,
|
|
20
21
|
getMarketplacesCacheDir,
|
|
21
22
|
getMarketplacesRegistryPath,
|
|
@@ -27,7 +28,7 @@ import { matchesAppInterrupt } from "../../utils/keybinding-matchers";
|
|
|
27
28
|
import { DynamicBorder } from "../dynamic-border";
|
|
28
29
|
import { PluginInspectorPane } from "./plugin-inspector-pane";
|
|
29
30
|
import { PluginListPane } from "./plugin-list-pane";
|
|
30
|
-
import { applySearch,
|
|
31
|
+
import { applySearch, createInitialState, filterByTab, refreshState } from "./state-manager";
|
|
31
32
|
import type { DashboardPlugin, PluginDashboardState, PluginTabId } from "./types";
|
|
32
33
|
|
|
33
34
|
const DEFAULT_MARKETPLACE = "f5-sales-demo/marketplace";
|
|
@@ -113,14 +114,16 @@ export class PluginDashboard extends Container {
|
|
|
113
114
|
// Network failure on first run is fine — continue with whatever is available
|
|
114
115
|
}
|
|
115
116
|
|
|
117
|
+
let refreshWarning: string | undefined;
|
|
116
118
|
try {
|
|
117
|
-
await this.#mgr.
|
|
118
|
-
} catch {
|
|
119
|
-
|
|
119
|
+
refreshWarning = formatMarketplaceRefreshWarning(await this.#mgr.refreshMarketplaces());
|
|
120
|
+
} catch (error) {
|
|
121
|
+
refreshWarning = `Warning: Marketplace refresh failed. Showing last-known catalog data where available (offline/stale): ${error instanceof Error ? error.message : String(error)}`;
|
|
120
122
|
}
|
|
121
123
|
|
|
122
124
|
try {
|
|
123
125
|
this.#state = await createInitialState(this.#mgr, this.#npmMgr);
|
|
126
|
+
this.#state.warning = refreshWarning ?? null;
|
|
124
127
|
} catch (error) {
|
|
125
128
|
this.#state = {
|
|
126
129
|
tabs: [{ id: "installed", label: "Installed", count: 0 }],
|
|
@@ -132,6 +135,7 @@ export class PluginDashboard extends Container {
|
|
|
132
135
|
selectedIndex: 0,
|
|
133
136
|
scrollOffset: 0,
|
|
134
137
|
notice: null,
|
|
138
|
+
warning: refreshWarning ?? null,
|
|
135
139
|
loading: false,
|
|
136
140
|
loadError: error instanceof Error ? error.message : String(error),
|
|
137
141
|
};
|
|
@@ -197,30 +201,15 @@ export class PluginDashboard extends Container {
|
|
|
197
201
|
this.#buildLayout();
|
|
198
202
|
}
|
|
199
203
|
|
|
200
|
-
async #reloadData(): Promise<void> {
|
|
204
|
+
async #reloadData(refreshRemote = false): Promise<void> {
|
|
201
205
|
this.#state.loading = true;
|
|
202
206
|
this.#state.loadError = null;
|
|
203
207
|
this.#buildLayout();
|
|
204
208
|
|
|
205
209
|
try {
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
const prevTabId = this.#activeTabId();
|
|
210
|
-
const nextTabIndex = Math.max(
|
|
211
|
-
0,
|
|
212
|
-
tabs.findIndex(t => t.id === prevTabId),
|
|
213
|
-
);
|
|
214
|
-
|
|
215
|
-
this.#state.allPlugins = allPlugins;
|
|
216
|
-
this.#state.tabs = tabs;
|
|
217
|
-
this.#state.activeTabIndex = nextTabIndex;
|
|
218
|
-
this.#applyFilters();
|
|
219
|
-
|
|
220
|
-
if (selectedId) {
|
|
221
|
-
const idx = this.#state.searchFiltered.findIndex(p => p.id === selectedId);
|
|
222
|
-
if (idx >= 0) this.#state.selectedIndex = idx;
|
|
223
|
-
}
|
|
210
|
+
const refresh = refreshRemote ? await this.#mgr.refreshMarketplaces() : undefined;
|
|
211
|
+
this.#state = await refreshState(this.#state, this.#mgr, this.#npmMgr);
|
|
212
|
+
if (refresh) this.#state.warning = formatMarketplaceRefreshWarning(refresh) ?? null;
|
|
224
213
|
this.#clampSelection();
|
|
225
214
|
} catch (error) {
|
|
226
215
|
this.#state.loadError = error instanceof Error ? error.message : String(error);
|
|
@@ -266,6 +255,8 @@ export class PluginDashboard extends Container {
|
|
|
266
255
|
this.#rebuildAndRender();
|
|
267
256
|
|
|
268
257
|
try {
|
|
258
|
+
const refresh = await this.#mgr.refreshMarketplaces([plugin.marketplace]);
|
|
259
|
+
this.#state.warning = formatMarketplaceRefreshWarning(refresh) ?? null;
|
|
269
260
|
await this.#mgr.installPlugin(plugin.name, plugin.marketplace);
|
|
270
261
|
this.#state.notice = `Installed ${plugin.name}`;
|
|
271
262
|
await this.#reloadData();
|
|
@@ -353,7 +344,9 @@ export class PluginDashboard extends Container {
|
|
|
353
344
|
this.#rebuildAndRender();
|
|
354
345
|
|
|
355
346
|
try {
|
|
356
|
-
await this.#mgr.
|
|
347
|
+
const refresh = await this.#mgr.refreshMarketplaces(plugin.marketplace ? [plugin.marketplace] : undefined);
|
|
348
|
+
this.#state.warning = formatMarketplaceRefreshWarning(refresh) ?? null;
|
|
349
|
+
await this.#mgr.upgradePlugin(plugin.id, plugin.scope);
|
|
357
350
|
this.#state.notice = t("plugins.dashboard.upgraded", { name: plugin.name });
|
|
358
351
|
await this.#reloadData();
|
|
359
352
|
} catch (error) {
|
|
@@ -409,6 +402,11 @@ export class PluginDashboard extends Container {
|
|
|
409
402
|
this.addChild(new Spacer(1));
|
|
410
403
|
}
|
|
411
404
|
|
|
405
|
+
if (this.#state.warning) {
|
|
406
|
+
this.addChild(new Text(theme.fg("warning", replaceTabs(this.#state.warning)), 0, 0));
|
|
407
|
+
this.addChild(new Spacer(1));
|
|
408
|
+
}
|
|
409
|
+
|
|
412
410
|
if (this.#state.loading) {
|
|
413
411
|
this.addChild(new Text(theme.fg("muted", "Loading plugins..."), 0, 0));
|
|
414
412
|
this.addChild(new Spacer(1));
|
|
@@ -498,7 +496,7 @@ export class PluginDashboard extends Container {
|
|
|
498
496
|
}
|
|
499
497
|
|
|
500
498
|
if (matchesKey(data, "ctrl+r")) {
|
|
501
|
-
void this.#reloadData();
|
|
499
|
+
void this.#reloadData(true);
|
|
502
500
|
return;
|
|
503
501
|
}
|
|
504
502
|
|
|
@@ -204,6 +204,7 @@ export async function refreshState(
|
|
|
204
204
|
mgr: MarketplaceManager,
|
|
205
205
|
npmMgr: PluginManager,
|
|
206
206
|
): Promise<PluginDashboardState> {
|
|
207
|
+
const selectedId = state.searchFiltered[state.selectedIndex]?.id;
|
|
207
208
|
const allPlugins = await loadAllPlugins(mgr, npmMgr);
|
|
208
209
|
const tabs = buildTabs(allPlugins);
|
|
209
210
|
const prevTabId = state.tabs[state.activeTabIndex]?.id ?? "installed";
|
|
@@ -215,7 +216,7 @@ export async function refreshState(
|
|
|
215
216
|
const tabFiltered = filterByTab(allPlugins, activeTab?.id ?? "installed");
|
|
216
217
|
const searchFiltered = applySearch(tabFiltered, state.searchQuery);
|
|
217
218
|
|
|
218
|
-
|
|
219
|
+
const nextState = {
|
|
219
220
|
...state,
|
|
220
221
|
tabs,
|
|
221
222
|
activeTabIndex: nextTabIndex,
|
|
@@ -226,4 +227,15 @@ export async function refreshState(
|
|
|
226
227
|
loading: false,
|
|
227
228
|
loadError: null,
|
|
228
229
|
};
|
|
230
|
+
if (selectedId) {
|
|
231
|
+
const selectedIndex = searchFiltered.findIndex(plugin => plugin.id === selectedId);
|
|
232
|
+
if (selectedIndex >= 0) nextState.selectedIndex = selectedIndex;
|
|
233
|
+
}
|
|
234
|
+
if (searchFiltered.length === 0) {
|
|
235
|
+
nextState.selectedIndex = 0;
|
|
236
|
+
nextState.scrollOffset = 0;
|
|
237
|
+
} else {
|
|
238
|
+
nextState.selectedIndex = Math.max(0, Math.min(nextState.selectedIndex, searchFiltered.length - 1));
|
|
239
|
+
}
|
|
240
|
+
return nextState;
|
|
229
241
|
}
|
|
@@ -58,6 +58,14 @@ export const OPENAI_CODEX_LOGIN_MODEL_CHOICE: LoginModelChoice = {
|
|
|
58
58
|
thinkingLevel: ThinkingLevel.Medium,
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
+
export const ANTHROPIC_LOGIN_MODEL_CHOICE: LoginModelChoice = {
|
|
62
|
+
label: "Claude Sonnet 5",
|
|
63
|
+
description: "Claude subscription default with medium thinking",
|
|
64
|
+
provider: "anthropic",
|
|
65
|
+
modelId: "claude-sonnet-5",
|
|
66
|
+
thinkingLevel: ThinkingLevel.Medium,
|
|
67
|
+
};
|
|
68
|
+
|
|
61
69
|
export function getAvailableLiteLLMLoginModelChoices(availableModelIds: readonly string[]): LiteLLMLoginModelChoice[] {
|
|
62
70
|
const available = new Set(availableModelIds);
|
|
63
71
|
return LITELLM_LOGIN_MODEL_CHOICES.filter(choice => available.has(choice.modelId));
|
|
@@ -103,7 +111,7 @@ interface ModelApplicableSession extends BaseModelApplicableSession {
|
|
|
103
111
|
thinkingLevel?: ThinkingLevel;
|
|
104
112
|
modelRegistry: {
|
|
105
113
|
getAll(): Model[];
|
|
106
|
-
getProviderDiscoveryState?(provider: string): { status: string; stale: boolean } | undefined;
|
|
114
|
+
getProviderDiscoveryState?(provider: string): { status: string; stale: boolean; models: string[] } | undefined;
|
|
107
115
|
};
|
|
108
116
|
settings?: Pick<Settings, "getModelRoles" | "get" | "set">;
|
|
109
117
|
setModelTemporary?(model: Model, thinkingLevel?: ThinkingLevel): Promise<void>;
|
|
@@ -144,11 +152,13 @@ export async function applyOAuthLoginModel(
|
|
|
144
152
|
): Promise<LoginModelChoice | undefined> {
|
|
145
153
|
const canonicalProvider = canonicalizeOAuthProviderId(providerId);
|
|
146
154
|
const choice =
|
|
147
|
-
canonicalProvider ===
|
|
148
|
-
?
|
|
149
|
-
: canonicalProvider ===
|
|
150
|
-
?
|
|
151
|
-
:
|
|
155
|
+
canonicalProvider === ANTHROPIC_LOGIN_MODEL_CHOICE.provider
|
|
156
|
+
? ANTHROPIC_LOGIN_MODEL_CHOICE
|
|
157
|
+
: canonicalProvider === GOOGLE_ANTIGRAVITY_LOGIN_MODEL_CHOICE.provider
|
|
158
|
+
? GOOGLE_ANTIGRAVITY_LOGIN_MODEL_CHOICE
|
|
159
|
+
: canonicalProvider === OPENAI_CODEX_LOGIN_MODEL_CHOICE.provider
|
|
160
|
+
? OPENAI_CODEX_LOGIN_MODEL_CHOICE
|
|
161
|
+
: undefined;
|
|
152
162
|
if (!choice) return undefined;
|
|
153
163
|
const discovery = session.modelRegistry.getProviderDiscoveryState?.(canonicalProvider);
|
|
154
164
|
if (session.modelRegistry.getProviderDiscoveryState && (discovery?.status !== "ok" || discovery.stale)) {
|
|
@@ -158,7 +168,9 @@ export async function applyOAuthLoginModel(
|
|
|
158
168
|
const settings = session.settings;
|
|
159
169
|
const storedProfile = settings?.get("routing.profile");
|
|
160
170
|
const previousProfile: "none" | SubscriptionProfileId =
|
|
161
|
-
storedProfile === "
|
|
171
|
+
storedProfile === "anthropic" || storedProfile === "google-antigravity" || storedProfile === "openai-codex"
|
|
172
|
+
? storedProfile
|
|
173
|
+
: "none";
|
|
162
174
|
const storedRoutingMode = settings?.get("routing.mode");
|
|
163
175
|
const previousRoutingMode =
|
|
164
176
|
storedRoutingMode === "shadow" || storedRoutingMode === "auto" ? storedRoutingMode : "off";
|
|
@@ -171,20 +183,26 @@ export async function applyOAuthLoginModel(
|
|
|
171
183
|
: {};
|
|
172
184
|
const previousModel = session.model;
|
|
173
185
|
const previousThinkingLevel = session.thinkingLevel;
|
|
186
|
+
let nextRoles: Record<string, string> | undefined;
|
|
174
187
|
if (settings) {
|
|
175
|
-
const available =
|
|
188
|
+
const available = discovery
|
|
189
|
+
? discovery.models.map(modelId => `${canonicalProvider}/${modelId}`)
|
|
190
|
+
: session.modelRegistry.getAll().map(model => `${model.provider}/${model.id}`);
|
|
176
191
|
const profile = applySubscriptionProfileRoles(
|
|
177
192
|
canonicalProvider as SubscriptionProfileId,
|
|
178
193
|
previousRoles,
|
|
179
194
|
available,
|
|
180
195
|
);
|
|
181
196
|
if (!profile.applied) return undefined;
|
|
182
|
-
|
|
183
|
-
settings.set("routing.mode", "off");
|
|
184
|
-
settings.set("routing.profile", canonicalProvider as SubscriptionProfileId);
|
|
197
|
+
nextRoles = profile.roles;
|
|
185
198
|
}
|
|
186
199
|
|
|
187
200
|
try {
|
|
201
|
+
if (settings && nextRoles) {
|
|
202
|
+
settings.set("modelRoles", nextRoles);
|
|
203
|
+
settings.set("routing.mode", "off");
|
|
204
|
+
settings.set("routing.profile", canonicalProvider as SubscriptionProfileId);
|
|
205
|
+
}
|
|
188
206
|
const applied = await applyModelAfterLogin(session, choice);
|
|
189
207
|
if (!applied && settings) {
|
|
190
208
|
settings.set("modelRoles", previousRoles);
|
|
@@ -26,6 +26,7 @@ import { DebugSelectorComponent } from "../../debug";
|
|
|
26
26
|
import { disableProvider, enableProvider } from "../../discovery";
|
|
27
27
|
import { clearXcshPluginRootsCache, resolveActiveProjectRegistryPath } from "../../discovery/helpers";
|
|
28
28
|
import {
|
|
29
|
+
formatMarketplaceRefreshWarning,
|
|
29
30
|
getInstalledPluginsRegistryPath,
|
|
30
31
|
getMarketplacesCacheDir,
|
|
31
32
|
getMarketplacesRegistryPath,
|
|
@@ -645,6 +646,9 @@ export class SelectorController {
|
|
|
645
646
|
},
|
|
646
647
|
});
|
|
647
648
|
|
|
649
|
+
const refresh = mode === "install" ? await mgr.refreshMarketplaces() : undefined;
|
|
650
|
+
const refreshWarning = refresh ? formatMarketplaceRefreshWarning(refresh) : undefined;
|
|
651
|
+
if (refreshWarning) this.ctx.showStatus(refreshWarning);
|
|
648
652
|
const [marketplaces, installed] = await Promise.all([mgr.listMarketplaces(), mgr.listInstalledPlugins()]);
|
|
649
653
|
const installedIds = new Set(installed.map(p => p.id));
|
|
650
654
|
|
|
@@ -692,7 +696,15 @@ export class SelectorController {
|
|
|
692
696
|
marketplace: string;
|
|
693
697
|
}> = [];
|
|
694
698
|
for (const mkt of marketplaces) {
|
|
695
|
-
|
|
699
|
+
let plugins: Awaited<ReturnType<typeof mgr.listAvailablePlugins>>;
|
|
700
|
+
try {
|
|
701
|
+
plugins = await mgr.listAvailablePlugins(mkt.name);
|
|
702
|
+
} catch (error) {
|
|
703
|
+
this.ctx.showStatus(
|
|
704
|
+
`${refreshWarning ? `${refreshWarning}\n` : ""}Marketplace ${mkt.name} is unavailable: ${error instanceof Error ? error.message : String(error)}`,
|
|
705
|
+
);
|
|
706
|
+
continue;
|
|
707
|
+
}
|
|
696
708
|
for (const plugin of plugins) {
|
|
697
709
|
allPlugins.push({ plugin, marketplace: mkt.name });
|
|
698
710
|
}
|
|
@@ -705,9 +717,13 @@ export class SelectorController {
|
|
|
705
717
|
this.ctx.showStatus(`Installing ${name} from ${marketplace}...`);
|
|
706
718
|
this.ctx.ui.requestRender();
|
|
707
719
|
try {
|
|
720
|
+
const installRefresh = await mgr.refreshMarketplaces([marketplace]);
|
|
721
|
+
const installWarning = formatMarketplaceRefreshWarning(installRefresh);
|
|
708
722
|
const force = installedIds.has(`${name}@${marketplace}`);
|
|
709
723
|
await mgr.installPlugin(name, marketplace, { force });
|
|
710
|
-
this.ctx.showStatus(
|
|
724
|
+
this.ctx.showStatus(
|
|
725
|
+
`${installWarning ? `${installWarning}\n` : ""}Installed ${name} from ${marketplace}`,
|
|
726
|
+
);
|
|
711
727
|
} catch (err) {
|
|
712
728
|
this.ctx.showStatus(`Install failed: ${err}`);
|
|
713
729
|
}
|
|
@@ -1260,7 +1276,13 @@ export class SelectorController {
|
|
|
1260
1276
|
const shouldOpenBrowser = providerId !== "openai-codex" || openAICodexMethod === "browser";
|
|
1261
1277
|
const loginCallbacks = {
|
|
1262
1278
|
method: openAICodexMethod,
|
|
1263
|
-
onAuth: (info: {
|
|
1279
|
+
onAuth: (info: {
|
|
1280
|
+
url: string;
|
|
1281
|
+
openUrl?: string;
|
|
1282
|
+
instructions?: string;
|
|
1283
|
+
kind?: "browser" | "device";
|
|
1284
|
+
userCode?: string;
|
|
1285
|
+
}) => {
|
|
1264
1286
|
this.ctx.chatContainer.addChild(new Spacer(1));
|
|
1265
1287
|
if (info.kind === "device" && info.userCode) {
|
|
1266
1288
|
presentDeviceCode(this.ctx.chatContainer, info.url, info.userCode);
|
|
@@ -1276,7 +1298,7 @@ export class SelectorController {
|
|
|
1276
1298
|
this.ctx.chatContainer.addChild(new Text(theme.fg("dim", MANUAL_LOGIN_TIP), 1, 0));
|
|
1277
1299
|
}
|
|
1278
1300
|
this.ctx.ui.requestRender();
|
|
1279
|
-
if (shouldOpenBrowser) this.ctx.openInBrowser(info.url);
|
|
1301
|
+
if (shouldOpenBrowser) this.ctx.openInBrowser(info.openUrl ?? info.url);
|
|
1280
1302
|
},
|
|
1281
1303
|
onPrompt: async (prompt: OAuthPrompt) => {
|
|
1282
1304
|
this.ctx.chatContainer.addChild(new Spacer(1));
|
|
@@ -1363,7 +1385,21 @@ export class SelectorController {
|
|
|
1363
1385
|
if (loginModelChoice) {
|
|
1364
1386
|
this.ctx.chatContainer.addChild(
|
|
1365
1387
|
new Text(
|
|
1366
|
-
theme.fg(
|
|
1388
|
+
theme.fg(
|
|
1389
|
+
"success",
|
|
1390
|
+
`Default model: ${loginModelChoice.provider}/${loginModelChoice.modelId}; ${formatLoginThinkingState(loginModelChoice.thinkingLevel)}`,
|
|
1391
|
+
),
|
|
1392
|
+
1,
|
|
1393
|
+
0,
|
|
1394
|
+
),
|
|
1395
|
+
);
|
|
1396
|
+
} else if (providerId === "anthropic") {
|
|
1397
|
+
this.ctx.chatContainer.addChild(
|
|
1398
|
+
new Text(
|
|
1399
|
+
theme.fg(
|
|
1400
|
+
"warning",
|
|
1401
|
+
"Claude login is valid, but fresh Haiku 4.5, Sonnet 5, and Opus 5 entitlements are required before changing the active profile. Use /model to select an available model.",
|
|
1402
|
+
),
|
|
1367
1403
|
1,
|
|
1368
1404
|
0,
|
|
1369
1405
|
),
|
package/src/routing/presets.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OPENAI_CODEX_ROUTING_POOL } from "./subscription-profiles";
|
|
1
|
+
import { ANTHROPIC_ROUTING_POOL, OPENAI_CODEX_ROUTING_POOL } from "./subscription-profiles";
|
|
2
2
|
import type { RoutingPoolConfig } from "./types";
|
|
3
3
|
|
|
4
4
|
export const BUILTIN_ROUTING_PRESETS: Record<string, RoutingPoolConfig> = {
|
|
@@ -12,15 +12,7 @@ export const BUILTIN_ROUTING_PRESETS: Record<string, RoutingPoolConfig> = {
|
|
|
12
12
|
frontier: "gpt-5.6-sol",
|
|
13
13
|
},
|
|
14
14
|
},
|
|
15
|
-
|
|
16
|
-
id: "anthropic/claude",
|
|
17
|
-
provider: "anthropic",
|
|
18
|
-
tiers: {
|
|
19
|
-
utility: "claude-3-haiku-20240307",
|
|
20
|
-
balanced: "claude-3-5-sonnet-20241022",
|
|
21
|
-
frontier: "claude-opus-4-0",
|
|
22
|
-
},
|
|
23
|
-
},
|
|
15
|
+
[ANTHROPIC_ROUTING_POOL.id]: ANTHROPIC_ROUTING_POOL,
|
|
24
16
|
"litellm/openai": {
|
|
25
17
|
id: "litellm/openai",
|
|
26
18
|
provider: "litellm",
|
package/src/routing/resolver.ts
CHANGED
|
@@ -30,14 +30,18 @@ export function resolveTierModel(
|
|
|
30
30
|
return { degraded: false, availableTiersCount: 0 };
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
const
|
|
33
|
+
const resolveAvailableSelector = (selector: string): string | undefined => {
|
|
34
34
|
if (pool.provider) {
|
|
35
35
|
const qualified = selector.includes("/") ? selector : `${pool.provider}/${selector}`;
|
|
36
|
-
const
|
|
37
|
-
|
|
36
|
+
const resolved =
|
|
37
|
+
availableModels.find(model => model === qualified || model === selector) ??
|
|
38
|
+
(pool.provider === "anthropic" && selector === "claude-haiku-4-5"
|
|
39
|
+
? availableModels.find(model => /^anthropic\/claude-haiku-4-5-\d{8}$/.test(model))
|
|
40
|
+
: undefined);
|
|
41
|
+
if (!resolved) return undefined;
|
|
38
42
|
|
|
39
43
|
if (options?.contextEstimate && options?.getModelContextWindow) {
|
|
40
|
-
const candidateWin = options.getModelContextWindow(
|
|
44
|
+
const candidateWin = options.getModelContextWindow(resolved) || options.getModelContextWindow(selector);
|
|
41
45
|
if (
|
|
42
46
|
candidateWin > 0 &&
|
|
43
47
|
!checkCandidateContextEligible({
|
|
@@ -46,17 +50,16 @@ export function resolveTierModel(
|
|
|
46
50
|
reserveTokens: options.contextEstimate.reserveTokens,
|
|
47
51
|
})
|
|
48
52
|
) {
|
|
49
|
-
return
|
|
53
|
+
return undefined;
|
|
50
54
|
}
|
|
51
55
|
}
|
|
52
|
-
return
|
|
56
|
+
return resolved.includes("/") ? resolved : qualified;
|
|
53
57
|
}
|
|
54
58
|
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (!inAvailable) return false;
|
|
59
|
+
const resolved = availableModels.find(
|
|
60
|
+
model => model === selector || (model.includes("/") && model.split("/")[1] === selector),
|
|
61
|
+
);
|
|
62
|
+
if (!resolved) return undefined;
|
|
60
63
|
|
|
61
64
|
if (options?.contextEstimate && options?.getModelContextWindow) {
|
|
62
65
|
const candidateWin = options.getModelContextWindow(selector);
|
|
@@ -68,36 +71,31 @@ export function resolveTierModel(
|
|
|
68
71
|
reserveTokens: options.contextEstimate.reserveTokens,
|
|
69
72
|
})
|
|
70
73
|
) {
|
|
71
|
-
return
|
|
74
|
+
return undefined;
|
|
72
75
|
}
|
|
73
76
|
}
|
|
74
77
|
|
|
75
|
-
return
|
|
78
|
+
return resolved;
|
|
76
79
|
};
|
|
77
80
|
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
+
const resolvedModels: Record<RoutingTier, string | undefined> = {
|
|
82
|
+
utility: resolveAvailableSelector(pool.tiers.utility),
|
|
83
|
+
balanced: resolveAvailableSelector(pool.tiers.balanced),
|
|
84
|
+
frontier: resolveAvailableSelector(pool.tiers.frontier),
|
|
85
|
+
};
|
|
81
86
|
|
|
82
87
|
const availableTiers: Record<RoutingTier, boolean> = {
|
|
83
|
-
utility:
|
|
84
|
-
balanced:
|
|
85
|
-
frontier:
|
|
88
|
+
utility: resolvedModels.utility !== undefined,
|
|
89
|
+
balanced: resolvedModels.balanced !== undefined,
|
|
90
|
+
frontier: resolvedModels.frontier !== undefined,
|
|
86
91
|
};
|
|
87
92
|
|
|
88
|
-
const availableCount =
|
|
93
|
+
const availableCount = Object.values(availableTiers).filter(Boolean).length;
|
|
89
94
|
|
|
90
95
|
if (availableCount < 2) {
|
|
91
96
|
return { degraded: true, availableTiersCount: availableCount };
|
|
92
97
|
}
|
|
93
98
|
|
|
94
|
-
const formatModel = (selector: string): string => {
|
|
95
|
-
if (pool.provider && !selector.includes("/")) {
|
|
96
|
-
return `${pool.provider}/${selector}`;
|
|
97
|
-
}
|
|
98
|
-
return selector;
|
|
99
|
-
};
|
|
100
|
-
|
|
101
99
|
const desiredIndex = TIER_ORDER.indexOf(desiredTier);
|
|
102
100
|
|
|
103
101
|
// Search desired tier, then higher tiers
|
|
@@ -105,7 +103,7 @@ export function resolveTierModel(
|
|
|
105
103
|
const tier = TIER_ORDER[i];
|
|
106
104
|
if (availableTiers[tier]) {
|
|
107
105
|
return {
|
|
108
|
-
selectedModel:
|
|
106
|
+
selectedModel: resolvedModels[tier],
|
|
109
107
|
effectiveTier: tier,
|
|
110
108
|
degraded: false,
|
|
111
109
|
availableTiersCount: availableCount,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { RoutingPoolConfig } from "./types";
|
|
2
2
|
|
|
3
|
-
export type SubscriptionProfileId = "google-antigravity" | "openai-codex";
|
|
3
|
+
export type SubscriptionProfileId = "anthropic" | "google-antigravity" | "openai-codex";
|
|
4
4
|
|
|
5
5
|
export interface SubscriptionRoutingProfile {
|
|
6
6
|
id: SubscriptionProfileId;
|
|
@@ -23,7 +23,32 @@ const OPENAI_CODEX_POOL: RoutingPoolConfig = {
|
|
|
23
23
|
},
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
+
const ANTHROPIC_POOL: RoutingPoolConfig = {
|
|
27
|
+
id: "anthropic/claude",
|
|
28
|
+
provider: "anthropic",
|
|
29
|
+
tiers: {
|
|
30
|
+
utility: "claude-haiku-4-5",
|
|
31
|
+
balanced: "claude-sonnet-5",
|
|
32
|
+
frontier: "claude-opus-5",
|
|
33
|
+
},
|
|
34
|
+
effortPolicy: {
|
|
35
|
+
byTier: { utility: "low", balanced: "medium", frontier: "high" },
|
|
36
|
+
frontierEscalation: { effort: "xhigh", minimumComplexityScore: 90 },
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
26
40
|
export const SUBSCRIPTION_ROUTING_PROFILES: Readonly<Record<SubscriptionProfileId, SubscriptionRoutingProfile>> = {
|
|
41
|
+
anthropic: {
|
|
42
|
+
id: "anthropic",
|
|
43
|
+
provider: "anthropic",
|
|
44
|
+
roles: {
|
|
45
|
+
smol: "anthropic/claude-haiku-4-5:low",
|
|
46
|
+
default: "anthropic/claude-sonnet-5:medium",
|
|
47
|
+
slow: "anthropic/claude-opus-5:high",
|
|
48
|
+
plan: "anthropic/claude-opus-5:high",
|
|
49
|
+
},
|
|
50
|
+
pool: ANTHROPIC_POOL,
|
|
51
|
+
},
|
|
27
52
|
"google-antigravity": {
|
|
28
53
|
id: "google-antigravity",
|
|
29
54
|
provider: "google-antigravity",
|
|
@@ -66,9 +91,10 @@ export function applySubscriptionProfileRoles(
|
|
|
66
91
|
): ApplySubscriptionProfileResult {
|
|
67
92
|
const profile = SUBSCRIPTION_ROUTING_PROFILES[profileId];
|
|
68
93
|
const available = new Set(availableModels);
|
|
94
|
+
const roles = profileId === "anthropic" ? resolveAnthropicRoles(availableModels, profile.roles) : profile.roles;
|
|
69
95
|
const missingModels = [
|
|
70
96
|
...new Set(
|
|
71
|
-
Object.values(
|
|
97
|
+
Object.values(roles)
|
|
72
98
|
.map(modelSelector)
|
|
73
99
|
.filter(model => !available.has(model)),
|
|
74
100
|
),
|
|
@@ -76,7 +102,19 @@ export function applySubscriptionProfileRoles(
|
|
|
76
102
|
if (missingModels.length > 0) {
|
|
77
103
|
return { applied: false, roles: { ...currentRoles }, missingModels };
|
|
78
104
|
}
|
|
79
|
-
return { applied: true, roles: { ...currentRoles, ...
|
|
105
|
+
return { applied: true, roles: { ...currentRoles, ...roles }, missingModels: [] };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function resolveAnthropicRoles(
|
|
109
|
+
availableModels: readonly string[],
|
|
110
|
+
fallback: Readonly<Record<"smol" | "default" | "slow" | "plan", string>>,
|
|
111
|
+
): Readonly<Record<"smol" | "default" | "slow" | "plan", string>> {
|
|
112
|
+
const haiku =
|
|
113
|
+
availableModels.find(selector => selector === "anthropic/claude-haiku-4-5") ??
|
|
114
|
+
availableModels.find(selector => /^anthropic\/claude-haiku-4-5-\d{8}$/.test(selector));
|
|
115
|
+
if (!haiku) return fallback;
|
|
116
|
+
return { ...fallback, smol: `${haiku}:low` };
|
|
80
117
|
}
|
|
81
118
|
|
|
82
119
|
export const OPENAI_CODEX_ROUTING_POOL = OPENAI_CODEX_POOL;
|
|
120
|
+
export const ANTHROPIC_ROUTING_POOL = ANTHROPIC_POOL;
|
|
@@ -1333,7 +1333,7 @@ export class AgentSession {
|
|
|
1333
1333
|
const resolved = applySubscriptionProfileRoles(
|
|
1334
1334
|
profileId,
|
|
1335
1335
|
currentRoles,
|
|
1336
|
-
|
|
1336
|
+
discovery.models.map(modelId => `${profileId}/${modelId}`),
|
|
1337
1337
|
);
|
|
1338
1338
|
if (!resolved.applied) return { applied: false, missingModels: resolved.missingModels };
|
|
1339
1339
|
|