bashio 1.1.0 → 1.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/dist/index.js +256 -152
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/cli/index.ts
|
|
4
|
-
import { createRequire } from "module";
|
|
5
4
|
import { Builtins, Cli } from "clipanion";
|
|
6
5
|
import pc17 from "picocolors";
|
|
7
6
|
import updateNotifier from "update-notifier";
|
|
@@ -83,13 +82,24 @@ var Settings = z.object({
|
|
|
83
82
|
historyMaxEntries: z.number().default(2e3),
|
|
84
83
|
autoConfirmShortcuts: z.boolean().default(false)
|
|
85
84
|
});
|
|
86
|
-
var
|
|
87
|
-
version: z.
|
|
85
|
+
var ConfigV1 = z.object({
|
|
86
|
+
version: z.literal(1).default(1),
|
|
88
87
|
provider: ProviderName,
|
|
89
88
|
model: z.string(),
|
|
90
89
|
credentials: Credentials,
|
|
91
90
|
settings: Settings.optional()
|
|
92
91
|
});
|
|
92
|
+
var ProviderSettings = z.object({
|
|
93
|
+
model: z.string(),
|
|
94
|
+
credentials: Credentials
|
|
95
|
+
});
|
|
96
|
+
var ConfigV2 = z.object({
|
|
97
|
+
version: z.literal(2),
|
|
98
|
+
activeProvider: ProviderName,
|
|
99
|
+
providers: z.record(z.string(), ProviderSettings),
|
|
100
|
+
settings: Settings.optional()
|
|
101
|
+
});
|
|
102
|
+
var Config = z.union([ConfigV2, ConfigV1]);
|
|
93
103
|
var ShortcutDefinition = z.object({
|
|
94
104
|
template: z.string(),
|
|
95
105
|
args: z.array(z.string()).default([]),
|
|
@@ -133,6 +143,19 @@ function ensureConfigDir() {
|
|
|
133
143
|
function configExists() {
|
|
134
144
|
return existsSync(CONFIG_FILE);
|
|
135
145
|
}
|
|
146
|
+
function migrateV1toV2(v1) {
|
|
147
|
+
return {
|
|
148
|
+
version: 2,
|
|
149
|
+
activeProvider: v1.provider,
|
|
150
|
+
providers: {
|
|
151
|
+
[v1.provider]: {
|
|
152
|
+
model: v1.model,
|
|
153
|
+
credentials: v1.credentials
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
settings: v1.settings
|
|
157
|
+
};
|
|
158
|
+
}
|
|
136
159
|
function loadConfig() {
|
|
137
160
|
if (!configExists()) {
|
|
138
161
|
return null;
|
|
@@ -140,7 +163,17 @@ function loadConfig() {
|
|
|
140
163
|
try {
|
|
141
164
|
const raw = readFileSync(CONFIG_FILE, "utf-8");
|
|
142
165
|
const data = JSON.parse(raw);
|
|
143
|
-
|
|
166
|
+
const v2Result = ConfigV2.safeParse(data);
|
|
167
|
+
if (v2Result.success) {
|
|
168
|
+
return v2Result.data;
|
|
169
|
+
}
|
|
170
|
+
const v1Result = ConfigV1.safeParse(data);
|
|
171
|
+
if (v1Result.success) {
|
|
172
|
+
const migrated = migrateV1toV2(v1Result.data);
|
|
173
|
+
saveConfig(migrated);
|
|
174
|
+
return migrated;
|
|
175
|
+
}
|
|
176
|
+
return null;
|
|
144
177
|
} catch {
|
|
145
178
|
return null;
|
|
146
179
|
}
|
|
@@ -157,6 +190,19 @@ function getConfigPath() {
|
|
|
157
190
|
function getConfigDir() {
|
|
158
191
|
return CONFIG_DIR;
|
|
159
192
|
}
|
|
193
|
+
function isProviderConfigured(config, provider) {
|
|
194
|
+
return provider in config.providers;
|
|
195
|
+
}
|
|
196
|
+
function setProviderConfig(config, provider, settings, setActive = true) {
|
|
197
|
+
return {
|
|
198
|
+
...config,
|
|
199
|
+
activeProvider: setActive ? provider : config.activeProvider,
|
|
200
|
+
providers: {
|
|
201
|
+
...config.providers,
|
|
202
|
+
[provider]: settings
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
}
|
|
160
206
|
|
|
161
207
|
// src/core/database.ts
|
|
162
208
|
import { chmodSync as chmodSync2, existsSync as existsSync2 } from "fs";
|
|
@@ -1063,16 +1109,17 @@ var ChatGPTSubscriptionProvider = class {
|
|
|
1063
1109
|
this.accountId = extractAccountIdFromToken(this.accessToken);
|
|
1064
1110
|
}
|
|
1065
1111
|
const currentConfig = loadConfig();
|
|
1066
|
-
|
|
1067
|
-
|
|
1112
|
+
const providerSettings = currentConfig?.providers["chatgpt-subscription"];
|
|
1113
|
+
if (currentConfig && providerSettings?.credentials.type === "chatgpt_subscription") {
|
|
1114
|
+
providerSettings.credentials.accessToken = newTokens.accessToken;
|
|
1068
1115
|
if (newTokens.refreshToken) {
|
|
1069
|
-
|
|
1116
|
+
providerSettings.credentials.refreshToken = newTokens.refreshToken;
|
|
1070
1117
|
}
|
|
1071
1118
|
if (newTokens.expiresAt) {
|
|
1072
|
-
|
|
1119
|
+
providerSettings.credentials.expiresAt = newTokens.expiresAt;
|
|
1073
1120
|
}
|
|
1074
1121
|
if (this.accountId) {
|
|
1075
|
-
|
|
1122
|
+
providerSettings.credentials.accountId = this.accountId;
|
|
1076
1123
|
}
|
|
1077
1124
|
saveConfig(currentConfig);
|
|
1078
1125
|
}
|
|
@@ -1321,10 +1368,11 @@ var ClaudeSubscriptionProvider = class {
|
|
|
1321
1368
|
this.refreshToken = newTokens.refreshToken;
|
|
1322
1369
|
this.expiresAt = newTokens.expiresAt;
|
|
1323
1370
|
const currentConfig = loadConfig();
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1371
|
+
const providerSettings = currentConfig?.providers["claude-subscription"];
|
|
1372
|
+
if (currentConfig && providerSettings?.credentials.type === "claude_subscription") {
|
|
1373
|
+
providerSettings.credentials.accessToken = newTokens.accessToken;
|
|
1374
|
+
providerSettings.credentials.refreshToken = newTokens.refreshToken;
|
|
1375
|
+
providerSettings.credentials.expiresAt = newTokens.expiresAt;
|
|
1328
1376
|
saveConfig(currentConfig);
|
|
1329
1377
|
}
|
|
1330
1378
|
} catch (error) {
|
|
@@ -1485,10 +1533,11 @@ var CopilotProvider = class {
|
|
|
1485
1533
|
this.copilotTokenExpiresAt = parsed.expiresAt;
|
|
1486
1534
|
this.apiEndpoint = parsed.apiEndpoint;
|
|
1487
1535
|
const currentConfig = loadConfig();
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1536
|
+
const providerSettings = currentConfig?.providers.copilot;
|
|
1537
|
+
if (currentConfig && providerSettings?.credentials.type === "copilot") {
|
|
1538
|
+
providerSettings.credentials.copilotToken = newTokenData.token;
|
|
1539
|
+
providerSettings.credentials.copilotTokenExpiresAt = parsed.expiresAt;
|
|
1540
|
+
providerSettings.credentials.apiEndpoint = parsed.apiEndpoint;
|
|
1492
1541
|
saveConfig(currentConfig);
|
|
1493
1542
|
}
|
|
1494
1543
|
} catch (error) {
|
|
@@ -1836,27 +1885,35 @@ var OPENROUTER_MODELS = [
|
|
|
1836
1885
|
|
|
1837
1886
|
// src/providers/index.ts
|
|
1838
1887
|
function createProvider(config) {
|
|
1888
|
+
const activeProvider = config.activeProvider;
|
|
1889
|
+
const settings = config.providers[activeProvider];
|
|
1890
|
+
if (!settings) {
|
|
1891
|
+
throw new Error(`Provider ${activeProvider} not configured`);
|
|
1892
|
+
}
|
|
1839
1893
|
const providerConfig = {
|
|
1840
|
-
model:
|
|
1841
|
-
credentials:
|
|
1894
|
+
model: settings.model,
|
|
1895
|
+
credentials: settings.credentials
|
|
1842
1896
|
};
|
|
1843
|
-
|
|
1897
|
+
return createProviderFromType(activeProvider, providerConfig);
|
|
1898
|
+
}
|
|
1899
|
+
function createProviderFromType(provider, config) {
|
|
1900
|
+
switch (provider) {
|
|
1844
1901
|
case "claude":
|
|
1845
|
-
return new ClaudeProvider(
|
|
1902
|
+
return new ClaudeProvider(config);
|
|
1846
1903
|
case "claude-subscription":
|
|
1847
|
-
return new ClaudeSubscriptionProvider(
|
|
1904
|
+
return new ClaudeSubscriptionProvider(config);
|
|
1848
1905
|
case "openai":
|
|
1849
|
-
return new OpenAIProvider(
|
|
1906
|
+
return new OpenAIProvider(config);
|
|
1850
1907
|
case "chatgpt-subscription":
|
|
1851
|
-
return new ChatGPTSubscriptionProvider(
|
|
1908
|
+
return new ChatGPTSubscriptionProvider(config);
|
|
1852
1909
|
case "copilot":
|
|
1853
|
-
return new CopilotProvider(
|
|
1910
|
+
return new CopilotProvider(config);
|
|
1854
1911
|
case "ollama":
|
|
1855
|
-
return new OllamaProvider(
|
|
1912
|
+
return new OllamaProvider(config);
|
|
1856
1913
|
case "openrouter":
|
|
1857
|
-
return new OpenRouterProvider(
|
|
1914
|
+
return new OpenRouterProvider(config);
|
|
1858
1915
|
default:
|
|
1859
|
-
throw new Error(`Unknown provider: ${
|
|
1916
|
+
throw new Error(`Unknown provider: ${provider}`);
|
|
1860
1917
|
}
|
|
1861
1918
|
}
|
|
1862
1919
|
|
|
@@ -1870,6 +1927,15 @@ function createSpinner(text) {
|
|
|
1870
1927
|
}
|
|
1871
1928
|
|
|
1872
1929
|
// src/core/auth.ts
|
|
1930
|
+
var PROVIDER_DISPLAY_NAMES = {
|
|
1931
|
+
"claude-subscription": "Claude Pro/Max",
|
|
1932
|
+
"chatgpt-subscription": "ChatGPT Plus/Pro",
|
|
1933
|
+
copilot: "GitHub Copilot",
|
|
1934
|
+
claude: "Claude (API Key)",
|
|
1935
|
+
openai: "ChatGPT (API Key)",
|
|
1936
|
+
ollama: "Ollama (Local)",
|
|
1937
|
+
openrouter: "OpenRouter"
|
|
1938
|
+
};
|
|
1873
1939
|
async function openBrowser(url) {
|
|
1874
1940
|
try {
|
|
1875
1941
|
const { exec: exec2 } = await import("child_process");
|
|
@@ -1943,6 +2009,7 @@ async function runAuthSetup(showBanner = true) {
|
|
|
1943
2009
|
showWelcomeBanner();
|
|
1944
2010
|
}
|
|
1945
2011
|
console.log(pc3.bold(" Bashio Setup\n"));
|
|
2012
|
+
const existingConfig = loadConfig();
|
|
1946
2013
|
const provider = await select({
|
|
1947
2014
|
message: "Select your AI provider:",
|
|
1948
2015
|
choices: [
|
|
@@ -1983,6 +2050,26 @@ async function runAuthSetup(showBanner = true) {
|
|
|
1983
2050
|
}
|
|
1984
2051
|
]
|
|
1985
2052
|
});
|
|
2053
|
+
if (existingConfig && isProviderConfigured(existingConfig, provider)) {
|
|
2054
|
+
const currentModel = existingConfig.providers[provider]?.model;
|
|
2055
|
+
console.log();
|
|
2056
|
+
console.log(
|
|
2057
|
+
pc3.yellow(` ${PROVIDER_DISPLAY_NAMES[provider]} is already configured.`)
|
|
2058
|
+
);
|
|
2059
|
+
console.log(pc3.dim(` Current model: ${currentModel}`));
|
|
2060
|
+
console.log();
|
|
2061
|
+
const action = await select({
|
|
2062
|
+
message: "What would you like to do?",
|
|
2063
|
+
choices: [
|
|
2064
|
+
{ value: "reauth", name: "Update credentials (re-authenticate)" },
|
|
2065
|
+
{ value: "cancel", name: "Cancel" }
|
|
2066
|
+
]
|
|
2067
|
+
});
|
|
2068
|
+
if (action === "cancel") {
|
|
2069
|
+
console.log(pc3.dim("\n Cancelled.\n"));
|
|
2070
|
+
return false;
|
|
2071
|
+
}
|
|
2072
|
+
}
|
|
1986
2073
|
let credentials;
|
|
1987
2074
|
let model;
|
|
1988
2075
|
switch (provider) {
|
|
@@ -2158,12 +2245,12 @@ async function runAuthSetup(showBanner = true) {
|
|
|
2158
2245
|
default:
|
|
2159
2246
|
throw new Error(`Unknown provider: ${provider}`);
|
|
2160
2247
|
}
|
|
2161
|
-
const
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
settings: {
|
|
2248
|
+
const providerSettings = { model, credentials };
|
|
2249
|
+
const tempConfig = {
|
|
2250
|
+
version: 2,
|
|
2251
|
+
activeProvider: provider,
|
|
2252
|
+
providers: { [provider]: providerSettings },
|
|
2253
|
+
settings: existingConfig?.settings || {
|
|
2167
2254
|
confirmBeforeExecute: true,
|
|
2168
2255
|
historyEnabled: true,
|
|
2169
2256
|
historyRetentionDays: 30,
|
|
@@ -2173,7 +2260,7 @@ async function runAuthSetup(showBanner = true) {
|
|
|
2173
2260
|
};
|
|
2174
2261
|
const spinner = createSpinner("Validating credentials...").start();
|
|
2175
2262
|
try {
|
|
2176
|
-
const providerInstance = createProvider(
|
|
2263
|
+
const providerInstance = createProvider(tempConfig);
|
|
2177
2264
|
const valid = await providerInstance.validateCredentials();
|
|
2178
2265
|
if (!valid) {
|
|
2179
2266
|
spinner.fail("Invalid credentials");
|
|
@@ -2186,10 +2273,11 @@ async function runAuthSetup(showBanner = true) {
|
|
|
2186
2273
|
);
|
|
2187
2274
|
return false;
|
|
2188
2275
|
}
|
|
2189
|
-
|
|
2276
|
+
const finalConfig = existingConfig ? setProviderConfig(existingConfig, provider, providerSettings, true) : tempConfig;
|
|
2277
|
+
saveConfig(finalConfig);
|
|
2190
2278
|
console.log();
|
|
2191
2279
|
logger.success("Configuration saved!");
|
|
2192
|
-
console.log(pc3.gray(` Provider: ${provider}`));
|
|
2280
|
+
console.log(pc3.gray(` Provider: ${PROVIDER_DISPLAY_NAMES[provider]}`));
|
|
2193
2281
|
console.log(pc3.gray(` Model: ${model}`));
|
|
2194
2282
|
console.log();
|
|
2195
2283
|
return true;
|
|
@@ -2548,15 +2636,32 @@ var ConfigCommand = class extends Command4 {
|
|
|
2548
2636
|
logger.error("Failed to load configuration.");
|
|
2549
2637
|
return 1;
|
|
2550
2638
|
}
|
|
2639
|
+
const activeSettings = config.providers[config.activeProvider];
|
|
2640
|
+
const configuredProviders = Object.keys(config.providers);
|
|
2551
2641
|
console.log(pc7.bold("\n Bashio Configuration\n"));
|
|
2552
|
-
console.log(
|
|
2553
|
-
|
|
2554
|
-
|
|
2642
|
+
console.log(
|
|
2643
|
+
` Active Provider: ${pc7.cyan(PROVIDER_DISPLAY_NAMES[config.activeProvider])}`
|
|
2644
|
+
);
|
|
2645
|
+
console.log(
|
|
2646
|
+
` Model: ${pc7.cyan(activeSettings?.model || "N/A")}`
|
|
2647
|
+
);
|
|
2648
|
+
if (configuredProviders.length > 1) {
|
|
2649
|
+
console.log();
|
|
2650
|
+
console.log(pc7.bold(" Configured Providers"));
|
|
2651
|
+
for (const p of configuredProviders) {
|
|
2652
|
+
const settings2 = config.providers[p];
|
|
2653
|
+
const isActive = p === config.activeProvider;
|
|
2654
|
+
const marker = isActive ? pc7.green("\u25CF") : pc7.dim("\u25CB");
|
|
2655
|
+
console.log(
|
|
2656
|
+
` ${marker} ${PROVIDER_DISPLAY_NAMES[p]} - ${pc7.dim(settings2?.model || "N/A")}`
|
|
2657
|
+
);
|
|
2658
|
+
}
|
|
2659
|
+
}
|
|
2555
2660
|
const settings = config.settings;
|
|
2556
2661
|
console.log();
|
|
2557
2662
|
console.log(pc7.bold(" Settings"));
|
|
2558
2663
|
console.log(
|
|
2559
|
-
` History:
|
|
2664
|
+
` History: ${settings?.historyEnabled !== false ? pc7.green("enabled") : pc7.gray("disabled")}`
|
|
2560
2665
|
);
|
|
2561
2666
|
console.log(
|
|
2562
2667
|
` Auto-confirm shortcuts: ${settings?.autoConfirmShortcuts ? pc7.green("enabled") : pc7.gray("disabled")}`
|
|
@@ -3297,16 +3402,35 @@ var selectWithEsc = async (config) => {
|
|
|
3297
3402
|
}
|
|
3298
3403
|
};
|
|
3299
3404
|
var isPromptExit = (error) => {
|
|
3300
|
-
if (!(error instanceof Error))
|
|
3301
|
-
|
|
3302
|
-
}
|
|
3303
|
-
return error.name === "ExitPromptError" || error.name === "AbortPromptError" || error.name === "CancelPromptError";
|
|
3405
|
+
if (!(error instanceof Error)) return false;
|
|
3406
|
+
return error.name === "ExitPromptError" || error.name === "AbortPromptError" || error.name === "CancelPromptError" || error.message.includes("SIGINT") || error.message.includes("force closed");
|
|
3304
3407
|
};
|
|
3408
|
+
function getModelsForProvider(provider) {
|
|
3409
|
+
switch (provider) {
|
|
3410
|
+
case "claude":
|
|
3411
|
+
return CLAUDE_MODELS;
|
|
3412
|
+
case "claude-subscription":
|
|
3413
|
+
return CLAUDE_SUBSCRIPTION_MODELS;
|
|
3414
|
+
case "openai":
|
|
3415
|
+
return OPENAI_MODELS;
|
|
3416
|
+
case "chatgpt-subscription":
|
|
3417
|
+
return CHATGPT_SUBSCRIPTION_MODELS;
|
|
3418
|
+
case "copilot":
|
|
3419
|
+
return COPILOT_MODELS;
|
|
3420
|
+
case "openrouter":
|
|
3421
|
+
return OPENROUTER_MODELS;
|
|
3422
|
+
case "ollama":
|
|
3423
|
+
return [];
|
|
3424
|
+
// Handled separately
|
|
3425
|
+
default:
|
|
3426
|
+
return [];
|
|
3427
|
+
}
|
|
3428
|
+
}
|
|
3305
3429
|
var ModelCommand = class extends Command8 {
|
|
3306
3430
|
static paths = [["model"], ["--model"]];
|
|
3307
3431
|
static usage = Command8.Usage({
|
|
3308
|
-
description: "Change the AI
|
|
3309
|
-
examples: [["Change model", "$0 --model"]]
|
|
3432
|
+
description: "Change the AI provider and model",
|
|
3433
|
+
examples: [["Change provider/model", "$0 --model"]]
|
|
3310
3434
|
});
|
|
3311
3435
|
async execute() {
|
|
3312
3436
|
if (!configExists()) {
|
|
@@ -3321,103 +3445,95 @@ var ModelCommand = class extends Command8 {
|
|
|
3321
3445
|
logger.error("Failed to load configuration.");
|
|
3322
3446
|
return 1;
|
|
3323
3447
|
}
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3448
|
+
const configuredProviders = Object.keys(config.providers);
|
|
3449
|
+
if (configuredProviders.length === 0) {
|
|
3450
|
+
logger.warn("No providers configured.");
|
|
3451
|
+
console.log(pc12.gray("Run 'b --auth' to set up a provider.\n"));
|
|
3452
|
+
return 1;
|
|
3453
|
+
}
|
|
3454
|
+
const activeSettings = config.providers[config.activeProvider];
|
|
3455
|
+
console.log(pc12.bold("\n Change Provider & Model\n"));
|
|
3456
|
+
console.log(
|
|
3457
|
+
pc12.gray(
|
|
3458
|
+
` Current: ${PROVIDER_DISPLAY_NAMES[config.activeProvider]} / ${activeSettings?.model}`
|
|
3459
|
+
)
|
|
3460
|
+
);
|
|
3327
3461
|
console.log(pc12.dim(" Press Esc to cancel\n"));
|
|
3328
|
-
let newModel;
|
|
3329
3462
|
try {
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3463
|
+
const providerChoices = configuredProviders.map((p) => {
|
|
3464
|
+
const settings = config.providers[p];
|
|
3465
|
+
const isActive = p === config.activeProvider;
|
|
3466
|
+
const marker = isActive ? pc12.green("\u25CF") : pc12.dim("\u25CB");
|
|
3467
|
+
const name = `${marker} ${PROVIDER_DISPLAY_NAMES[p]}`;
|
|
3468
|
+
const description = settings?.model || "Not configured";
|
|
3469
|
+
return { value: p, name, description };
|
|
3470
|
+
});
|
|
3471
|
+
providerChoices.push({
|
|
3472
|
+
value: "__add_new__",
|
|
3473
|
+
name: pc12.cyan("+ Add new provider..."),
|
|
3474
|
+
description: "Configure a new AI provider"
|
|
3475
|
+
});
|
|
3476
|
+
const selectedProvider = await selectWithEsc({
|
|
3477
|
+
message: "Select provider:",
|
|
3478
|
+
choices: providerChoices
|
|
3479
|
+
});
|
|
3480
|
+
if (selectedProvider === "__add_new__") {
|
|
3481
|
+
console.log(pc12.dim("\n Run 'b --auth' to add a new provider.\n"));
|
|
3482
|
+
return 0;
|
|
3483
|
+
}
|
|
3484
|
+
const currentModel = config.providers[selectedProvider]?.model;
|
|
3485
|
+
let newModel;
|
|
3486
|
+
if (selectedProvider === "ollama") {
|
|
3487
|
+
const host = config.providers.ollama?.credentials.type === "local" ? config.providers.ollama.credentials.host : "http://localhost:11434";
|
|
3488
|
+
const spinner = createSpinner("Fetching available models...").start();
|
|
3489
|
+
const availableModels = await OllamaProvider.getAvailableModels(host);
|
|
3490
|
+
spinner.stop();
|
|
3491
|
+
if (availableModels.length === 0) {
|
|
3492
|
+
logger.warn("No models found. Make sure Ollama is running.");
|
|
3493
|
+
console.log(pc12.gray("\n Install a model: ollama pull llama3.2\n"));
|
|
3494
|
+
return 1;
|
|
3352
3495
|
}
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3496
|
+
newModel = await selectWithEsc({
|
|
3497
|
+
message: "Select model:",
|
|
3498
|
+
choices: availableModels.map((m) => ({ value: m, name: m })),
|
|
3499
|
+
default: currentModel
|
|
3500
|
+
});
|
|
3501
|
+
} else {
|
|
3502
|
+
const models = getModelsForProvider(selectedProvider);
|
|
3503
|
+
newModel = await selectWithEsc({
|
|
3504
|
+
message: "Select model:",
|
|
3505
|
+
choices: models.map((m) => ({ value: m.value, name: m.label })),
|
|
3506
|
+
default: currentModel
|
|
3507
|
+
});
|
|
3508
|
+
}
|
|
3509
|
+
const providerSettings = config.providers[selectedProvider];
|
|
3510
|
+
if (!providerSettings) {
|
|
3511
|
+
logger.error("Provider not configured.");
|
|
3512
|
+
return 1;
|
|
3513
|
+
}
|
|
3514
|
+
const updatedConfig = {
|
|
3515
|
+
...config,
|
|
3516
|
+
activeProvider: selectedProvider,
|
|
3517
|
+
providers: {
|
|
3518
|
+
...config.providers,
|
|
3519
|
+
[selectedProvider]: {
|
|
3520
|
+
...providerSettings,
|
|
3521
|
+
model: newModel
|
|
3362
3522
|
}
|
|
3363
|
-
newModel = await selectWithEsc({
|
|
3364
|
-
message: "Select new model:",
|
|
3365
|
-
choices: availableModels.map((m) => ({
|
|
3366
|
-
value: m,
|
|
3367
|
-
name: m
|
|
3368
|
-
})),
|
|
3369
|
-
default: config.model
|
|
3370
|
-
});
|
|
3371
|
-
break;
|
|
3372
|
-
}
|
|
3373
|
-
case "openrouter": {
|
|
3374
|
-
newModel = await selectWithEsc({
|
|
3375
|
-
message: "Select new model:",
|
|
3376
|
-
choices: OPENROUTER_MODELS.map((m) => ({
|
|
3377
|
-
value: m.value,
|
|
3378
|
-
name: m.label
|
|
3379
|
-
})),
|
|
3380
|
-
default: config.model
|
|
3381
|
-
});
|
|
3382
|
-
break;
|
|
3383
|
-
}
|
|
3384
|
-
case "claude-subscription": {
|
|
3385
|
-
newModel = await selectWithEsc({
|
|
3386
|
-
message: "Select new model:",
|
|
3387
|
-
choices: CLAUDE_SUBSCRIPTION_MODELS.map((m) => ({
|
|
3388
|
-
value: m.value,
|
|
3389
|
-
name: m.label
|
|
3390
|
-
})),
|
|
3391
|
-
default: config.model
|
|
3392
|
-
});
|
|
3393
|
-
break;
|
|
3394
|
-
}
|
|
3395
|
-
case "chatgpt-subscription": {
|
|
3396
|
-
newModel = await selectWithEsc({
|
|
3397
|
-
message: "Select new model:",
|
|
3398
|
-
choices: CHATGPT_SUBSCRIPTION_MODELS.map((m) => ({
|
|
3399
|
-
value: m.value,
|
|
3400
|
-
name: m.label
|
|
3401
|
-
})),
|
|
3402
|
-
default: config.model
|
|
3403
|
-
});
|
|
3404
|
-
break;
|
|
3405
|
-
}
|
|
3406
|
-
case "copilot": {
|
|
3407
|
-
newModel = await selectWithEsc({
|
|
3408
|
-
message: "Select new model:",
|
|
3409
|
-
choices: COPILOT_MODELS.map((m) => ({
|
|
3410
|
-
value: m.value,
|
|
3411
|
-
name: m.label
|
|
3412
|
-
})),
|
|
3413
|
-
default: config.model
|
|
3414
|
-
});
|
|
3415
|
-
break;
|
|
3416
3523
|
}
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3524
|
+
};
|
|
3525
|
+
saveConfig(updatedConfig);
|
|
3526
|
+
const changed = selectedProvider !== config.activeProvider || newModel !== currentModel;
|
|
3527
|
+
if (changed) {
|
|
3528
|
+
console.log();
|
|
3529
|
+
logger.success(
|
|
3530
|
+
`Switched to: ${PROVIDER_DISPLAY_NAMES[selectedProvider]} / ${newModel}`
|
|
3531
|
+
);
|
|
3532
|
+
} else {
|
|
3533
|
+
logger.info("No changes made.");
|
|
3420
3534
|
}
|
|
3535
|
+
console.log();
|
|
3536
|
+
return 0;
|
|
3421
3537
|
} catch (error) {
|
|
3422
3538
|
if (isPromptExit(error)) {
|
|
3423
3539
|
console.log(pc12.dim("\n Cancelled.\n"));
|
|
@@ -3425,16 +3541,6 @@ var ModelCommand = class extends Command8 {
|
|
|
3425
3541
|
}
|
|
3426
3542
|
throw error;
|
|
3427
3543
|
}
|
|
3428
|
-
if (newModel === config.model) {
|
|
3429
|
-
logger.info("Model unchanged.");
|
|
3430
|
-
return 0;
|
|
3431
|
-
}
|
|
3432
|
-
config.model = newModel;
|
|
3433
|
-
saveConfig(config);
|
|
3434
|
-
console.log();
|
|
3435
|
-
logger.success(`Model changed to: ${newModel}`);
|
|
3436
|
-
console.log();
|
|
3437
|
-
return 0;
|
|
3438
3544
|
}
|
|
3439
3545
|
};
|
|
3440
3546
|
|
|
@@ -3845,11 +3951,9 @@ var SuggestShortcutsCommand = class extends Command12 {
|
|
|
3845
3951
|
};
|
|
3846
3952
|
|
|
3847
3953
|
// src/cli/index.ts
|
|
3848
|
-
var require2 = createRequire(import.meta.url);
|
|
3849
|
-
var packageJson = require2("../../package.json");
|
|
3850
3954
|
var pkg = {
|
|
3851
|
-
name:
|
|
3852
|
-
version:
|
|
3955
|
+
name: "bashio",
|
|
3956
|
+
version: "1.1.1"
|
|
3853
3957
|
};
|
|
3854
3958
|
var notifier = updateNotifier({
|
|
3855
3959
|
pkg,
|