ohmyswitch 0.2.0 → 0.2.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/oms.mjs +107 -8
- package/package.json +1 -1
package/oms.mjs
CHANGED
|
@@ -217,6 +217,35 @@ const endpoints = [
|
|
|
217
217
|
"/v1beta/generateContent"
|
|
218
218
|
];
|
|
219
219
|
//#endregion
|
|
220
|
+
//#region src/core/vendors.ts
|
|
221
|
+
/**
|
|
222
|
+
* The model vendor a provider serves. It is shown as the badge on the provider's icon, and an import link names it
|
|
223
|
+
* to update an existing provider. The order is the display order; append new vendors at the end.
|
|
224
|
+
*/
|
|
225
|
+
const vendors = [
|
|
226
|
+
"openai",
|
|
227
|
+
"anthropic",
|
|
228
|
+
"google",
|
|
229
|
+
"deepseek",
|
|
230
|
+
"qwen",
|
|
231
|
+
"moonshot",
|
|
232
|
+
"zhipu",
|
|
233
|
+
"xai",
|
|
234
|
+
"mistral",
|
|
235
|
+
"meta",
|
|
236
|
+
"groq",
|
|
237
|
+
"minimax",
|
|
238
|
+
"doubao",
|
|
239
|
+
"hunyuan",
|
|
240
|
+
"baidu",
|
|
241
|
+
"openrouter",
|
|
242
|
+
"siliconcloud",
|
|
243
|
+
"stepfun",
|
|
244
|
+
"cohere",
|
|
245
|
+
"yi",
|
|
246
|
+
"baichuan"
|
|
247
|
+
];
|
|
248
|
+
//#endregion
|
|
220
249
|
//#region src/cli/commands/shared.ts
|
|
221
250
|
/** Protocol names of the endpoints, as the GUI shows them. */
|
|
222
251
|
const endpointLabels = {
|
|
@@ -225,6 +254,44 @@ const endpointLabels = {
|
|
|
225
254
|
"/v1/messages": "Anthropic Messages",
|
|
226
255
|
"/v1beta/generateContent": "Google Generative AI"
|
|
227
256
|
};
|
|
257
|
+
/** Vendor names, as the GUI shows them. */
|
|
258
|
+
const vendorLabels = {
|
|
259
|
+
openai: "OpenAI",
|
|
260
|
+
anthropic: "Anthropic",
|
|
261
|
+
google: "Google",
|
|
262
|
+
deepseek: "DeepSeek",
|
|
263
|
+
qwen: "Qwen",
|
|
264
|
+
moonshot: "Moonshot",
|
|
265
|
+
zhipu: "Zhipu",
|
|
266
|
+
xai: "xAI",
|
|
267
|
+
mistral: "Mistral",
|
|
268
|
+
meta: "Meta",
|
|
269
|
+
groq: "Groq",
|
|
270
|
+
minimax: "MiniMax",
|
|
271
|
+
doubao: "Doubao",
|
|
272
|
+
hunyuan: "Hunyuan",
|
|
273
|
+
baidu: "Baidu",
|
|
274
|
+
openrouter: "OpenRouter",
|
|
275
|
+
siliconcloud: "SiliconCloud",
|
|
276
|
+
stepfun: "StepFun",
|
|
277
|
+
cohere: "Cohere",
|
|
278
|
+
yi: "Yi",
|
|
279
|
+
baichuan: "Baichuan"
|
|
280
|
+
};
|
|
281
|
+
/** What --vendor accepts to leave the vendor unset, so the badge follows the endpoint. */
|
|
282
|
+
const followEndpoint = "follow";
|
|
283
|
+
const vendorChoices = () => [{
|
|
284
|
+
value: followEndpoint,
|
|
285
|
+
keys: [followEndpoint, "auto"],
|
|
286
|
+
label: "Follow the endpoint",
|
|
287
|
+
hint: "The badge of the endpoint's vendor"
|
|
288
|
+
}, ...vendors.map((vendor) => ({
|
|
289
|
+
value: vendor,
|
|
290
|
+
keys: [vendor],
|
|
291
|
+
label: vendorLabels[vendor],
|
|
292
|
+
hint: vendor === vendorLabels[vendor] ? void 0 : vendor
|
|
293
|
+
}))];
|
|
294
|
+
const vendorDetails = `One of ${listing(vendors)}, or ${followEndpoint} to show the endpoint's vendor`;
|
|
228
295
|
/** How an application's entry looks now. */
|
|
229
296
|
const applicationStateLabels = {
|
|
230
297
|
applied: "applied",
|
|
@@ -6608,6 +6675,11 @@ const storedProvider = object({
|
|
|
6608
6675
|
/** The root address requests go to; endpoints are appended to it. */
|
|
6609
6676
|
baseUrl,
|
|
6610
6677
|
endpoint: _enum(endpoints),
|
|
6678
|
+
/**
|
|
6679
|
+
* The model vendor, shown as the badge on the provider's icon and compared by import links. Unset means the
|
|
6680
|
+
* badge follows the endpoint. It is display information: it is not written into harness configs.
|
|
6681
|
+
*/
|
|
6682
|
+
vendor: _enum(vendors).optional(),
|
|
6611
6683
|
apiKey: string(),
|
|
6612
6684
|
/** An image or web page to take the icon from; unset uses the Base URL's site. */
|
|
6613
6685
|
iconUrl: url({ protocol: /^https?$/ }).optional(),
|
|
@@ -6643,12 +6715,14 @@ function effectiveModel(model, globalOverrides, providerOverrides = {}) {
|
|
|
6643
6715
|
//#endregion
|
|
6644
6716
|
//#region src/core/providers/schemas.ts
|
|
6645
6717
|
const providerIdInput = object({ providerId: uuid() });
|
|
6646
|
-
/** The
|
|
6718
|
+
/** The fields of a provider the editor saves together; they are not all connection details. */
|
|
6647
6719
|
const connectionInput = object({
|
|
6648
6720
|
name: providerName,
|
|
6649
6721
|
baseUrl,
|
|
6650
6722
|
apiKey: string().trim().min(1, { error: "请填写 API Key" }).max(4096),
|
|
6651
6723
|
endpoint: _enum(endpoints, { error: "请选择端点" }),
|
|
6724
|
+
/** Unset follows the endpoint, which is also how an import link without one compares. */
|
|
6725
|
+
vendor: _enum(vendors).optional(),
|
|
6652
6726
|
/** Unset or empty uses the icon of the Base URL's site. */
|
|
6653
6727
|
iconUrl: iconUrl.optional()
|
|
6654
6728
|
});
|
|
@@ -7024,13 +7098,14 @@ const show = command({
|
|
|
7024
7098
|
const ctx = await scope.services();
|
|
7025
7099
|
const harnesses = await harnessIndex(scope);
|
|
7026
7100
|
const detail = ctx.providers.get(provider.id);
|
|
7027
|
-
const { iconUrl } = ctx.providers.connection(provider.id);
|
|
7101
|
+
const { iconUrl, vendor } = ctx.providers.connection(provider.id);
|
|
7028
7102
|
const applications = (await ctx.harnesses.applications())[provider.id] ?? [];
|
|
7029
7103
|
return {
|
|
7030
7104
|
id: detail.id,
|
|
7031
7105
|
name: detail.name,
|
|
7032
7106
|
baseUrl: detail.baseUrl,
|
|
7033
7107
|
endpoint: detail.endpoint,
|
|
7108
|
+
vendor,
|
|
7034
7109
|
iconUrl: iconUrl || void 0,
|
|
7035
7110
|
...showKey ? { apiKey: ctx.providers.connection(provider.id).apiKey } : {},
|
|
7036
7111
|
createdAt: detail.createdAt,
|
|
@@ -7048,6 +7123,7 @@ const show = command({
|
|
|
7048
7123
|
["ID", provider.id],
|
|
7049
7124
|
["Base URL", provider.baseUrl],
|
|
7050
7125
|
["Endpoint", `${endpointLabels[provider.endpoint]} (${provider.endpoint})`],
|
|
7126
|
+
["Vendor", provider.vendor ? vendorLabels[provider.vendor] : `Follows the endpoint (${endpointLabels[provider.endpoint]})`],
|
|
7051
7127
|
["Icon", provider.iconUrl],
|
|
7052
7128
|
["API key", provider.apiKey]
|
|
7053
7129
|
]);
|
|
@@ -7109,6 +7185,13 @@ const add = command({
|
|
|
7109
7185
|
details: endpointDetails,
|
|
7110
7186
|
choices: endpointChoices
|
|
7111
7187
|
}),
|
|
7188
|
+
vendor: select$1({
|
|
7189
|
+
summary: "Model vendor",
|
|
7190
|
+
placeholder: "vendor",
|
|
7191
|
+
details: vendorDetails,
|
|
7192
|
+
optional: true,
|
|
7193
|
+
choices: vendorChoices
|
|
7194
|
+
}),
|
|
7112
7195
|
apiKey: secret({
|
|
7113
7196
|
summary: "API key",
|
|
7114
7197
|
parse: (raw) => parseWith(createProviderInput.shape.apiKey, raw)
|
|
@@ -7150,6 +7233,7 @@ const add = command({
|
|
|
7150
7233
|
name: values.name,
|
|
7151
7234
|
baseUrl: values.baseUrl,
|
|
7152
7235
|
endpoint: values.endpoint,
|
|
7236
|
+
vendor: values.vendor === "follow" ? void 0 : values.vendor,
|
|
7153
7237
|
apiKey: values.apiKey,
|
|
7154
7238
|
iconUrl: values.iconUrl,
|
|
7155
7239
|
...fetched ? {
|
|
@@ -7196,6 +7280,14 @@ const edit = command({
|
|
|
7196
7280
|
initial: (scope) => chosen(scope).endpoint,
|
|
7197
7281
|
choices: endpointChoices
|
|
7198
7282
|
}),
|
|
7283
|
+
vendor: select$1({
|
|
7284
|
+
summary: "Model vendor",
|
|
7285
|
+
placeholder: "vendor",
|
|
7286
|
+
details: vendorDetails,
|
|
7287
|
+
optional: true,
|
|
7288
|
+
initial: (scope) => chosen(scope).vendor ?? "follow",
|
|
7289
|
+
choices: vendorChoices
|
|
7290
|
+
}),
|
|
7199
7291
|
apiKey: secret({
|
|
7200
7292
|
summary: "API key",
|
|
7201
7293
|
optional: true,
|
|
@@ -7214,7 +7306,7 @@ const edit = command({
|
|
|
7214
7306
|
const ctx = await scope.services();
|
|
7215
7307
|
if (Object.values(changes).every((value) => value === void 0)) {
|
|
7216
7308
|
if (scope.session.interactive) return void 0;
|
|
7217
|
-
throw new CliError("usage", "Nothing to change", "Pass --name, --base-url, --endpoint, --icon-url, --api-key-stdin or --api-key-env.");
|
|
7309
|
+
throw new CliError("usage", "Nothing to change", "Pass --name, --base-url, --endpoint, --vendor, --icon-url, --api-key-stdin or --api-key-env.");
|
|
7218
7310
|
}
|
|
7219
7311
|
if (changes.name !== void 0) await assertNameFree(scope, changes.name, provider.id);
|
|
7220
7312
|
const current = ctx.providers.connection(provider.id);
|
|
@@ -7223,6 +7315,7 @@ const edit = command({
|
|
|
7223
7315
|
name: changes.name ?? current.name,
|
|
7224
7316
|
baseUrl: changes.baseUrl ?? current.baseUrl,
|
|
7225
7317
|
endpoint: changes.endpoint ?? current.endpoint,
|
|
7318
|
+
vendor: changes.vendor === "follow" ? void 0 : changes.vendor ?? current.vendor,
|
|
7226
7319
|
apiKey: changes.apiKey ?? current.apiKey,
|
|
7227
7320
|
iconUrl: changes.iconUrl ?? current.iconUrl
|
|
7228
7321
|
}));
|
|
@@ -7406,7 +7499,7 @@ function appDirs(home, env, platform) {
|
|
|
7406
7499
|
function loadConfig() {
|
|
7407
7500
|
const home = homedir();
|
|
7408
7501
|
return {
|
|
7409
|
-
version: "0.2.
|
|
7502
|
+
version: "0.2.1",
|
|
7410
7503
|
dirs: appDirs(home, process.env, process.platform),
|
|
7411
7504
|
home,
|
|
7412
7505
|
env: { ...process.env }
|
|
@@ -26508,14 +26601,15 @@ var ProviderService = class extends Service {
|
|
|
26508
26601
|
failures
|
|
26509
26602
|
};
|
|
26510
26603
|
}
|
|
26511
|
-
/** The
|
|
26604
|
+
/** The editable fields for the editor, the only place the API key is returned. */
|
|
26512
26605
|
connection(providerId) {
|
|
26513
|
-
const { name, baseUrl, apiKey, endpoint, iconUrl } = this.find(this.ctx.store.data.providers, providerId);
|
|
26606
|
+
const { name, baseUrl, apiKey, endpoint, vendor, iconUrl } = this.find(this.ctx.store.data.providers, providerId);
|
|
26514
26607
|
return {
|
|
26515
26608
|
name,
|
|
26516
26609
|
baseUrl,
|
|
26517
26610
|
apiKey,
|
|
26518
26611
|
endpoint,
|
|
26612
|
+
vendor,
|
|
26519
26613
|
iconUrl: iconUrl ?? ""
|
|
26520
26614
|
};
|
|
26521
26615
|
}
|
|
@@ -26683,6 +26777,8 @@ var ProviderService = class extends Service {
|
|
|
26683
26777
|
provider.baseUrl = input.baseUrl;
|
|
26684
26778
|
provider.apiKey = input.apiKey;
|
|
26685
26779
|
provider.endpoint = input.endpoint;
|
|
26780
|
+
if (input.vendor) provider.vendor = input.vendor;
|
|
26781
|
+
else delete provider.vendor;
|
|
26686
26782
|
if (input.iconUrl) provider.iconUrl = input.iconUrl;
|
|
26687
26783
|
else delete provider.iconUrl;
|
|
26688
26784
|
});
|
|
@@ -26704,6 +26800,7 @@ var ProviderService = class extends Service {
|
|
|
26704
26800
|
name: input.name,
|
|
26705
26801
|
baseUrl: input.baseUrl,
|
|
26706
26802
|
endpoint: input.endpoint,
|
|
26803
|
+
...input.vendor ? { vendor: input.vendor } : {},
|
|
26707
26804
|
apiKey: input.apiKey,
|
|
26708
26805
|
...input.iconUrl ? { iconUrl: input.iconUrl } : {},
|
|
26709
26806
|
models,
|
|
@@ -26833,6 +26930,7 @@ var ProviderService = class extends Service {
|
|
|
26833
26930
|
name: provider.name,
|
|
26834
26931
|
baseUrl: provider.baseUrl,
|
|
26835
26932
|
endpoint: provider.endpoint,
|
|
26933
|
+
vendor: provider.vendor,
|
|
26836
26934
|
modelCount: provider.models.length,
|
|
26837
26935
|
harnesses: this.ctx.harnesses.appliedTo(provider),
|
|
26838
26936
|
createdAt: provider.createdAt
|
|
@@ -26847,7 +26945,7 @@ var ProviderService = class extends Service {
|
|
|
26847
26945
|
//#endregion
|
|
26848
26946
|
//#region src/core/store/store.ts
|
|
26849
26947
|
const storeFile = object({
|
|
26850
|
-
version: literal(
|
|
26948
|
+
version: literal(6),
|
|
26851
26949
|
providers: array(storedProvider),
|
|
26852
26950
|
modelOverrides: record$2(string().min(1).max(256), modelOverride)
|
|
26853
26951
|
});
|
|
@@ -26855,7 +26953,7 @@ const fileName = "store.json";
|
|
|
26855
26953
|
/** Several writes in a row are read once, after the file has been quiet this long. */
|
|
26856
26954
|
const reloadDelayMs = 100;
|
|
26857
26955
|
const emptyStore = () => ({
|
|
26858
|
-
version:
|
|
26956
|
+
version: 6,
|
|
26859
26957
|
providers: [],
|
|
26860
26958
|
modelOverrides: {}
|
|
26861
26959
|
});
|
|
@@ -26873,6 +26971,7 @@ function migrate(raw) {
|
|
|
26873
26971
|
modelOverrides: {}
|
|
26874
26972
|
});
|
|
26875
26973
|
if (data.version === 4) data.version = 5;
|
|
26974
|
+
if (data.version === 5) data.version = 6;
|
|
26876
26975
|
return data;
|
|
26877
26976
|
}
|
|
26878
26977
|
/**
|