@cosmicstack/mercury-agent 1.1.2 → 1.1.3
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 +41 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -80,7 +80,7 @@ function getDefaultConfig() {
|
|
|
80
80
|
ollamaCloud: {
|
|
81
81
|
name: "ollamaCloud",
|
|
82
82
|
apiKey: getEnv("OLLAMA_CLOUD_API_KEY", ""),
|
|
83
|
-
baseUrl: getEnv("OLLAMA_CLOUD_BASE_URL", "https://ollama.com/
|
|
83
|
+
baseUrl: getEnv("OLLAMA_CLOUD_BASE_URL", "https://ollama.com/v1"),
|
|
84
84
|
model: getEnv("OLLAMA_CLOUD_MODEL", "gpt-oss:120b"),
|
|
85
85
|
enabled: getEnvBool("OLLAMA_CLOUD_ENABLED", true)
|
|
86
86
|
},
|
|
@@ -145,7 +145,9 @@ function loadConfig() {
|
|
|
145
145
|
const raw = readFileSync(CONFIG_PATH, "utf-8");
|
|
146
146
|
const fileConfig = parseYaml(raw);
|
|
147
147
|
const defaults = getDefaultConfig();
|
|
148
|
-
return
|
|
148
|
+
return migrateLegacyOllamaCloudBaseUrl(
|
|
149
|
+
migrateLegacyTelegramAccess(deepMerge(defaults, fileConfig))
|
|
150
|
+
);
|
|
149
151
|
}
|
|
150
152
|
return migrateLegacyTelegramAccess(getDefaultConfig());
|
|
151
153
|
}
|
|
@@ -189,6 +191,9 @@ function isProviderConfigured(provider) {
|
|
|
189
191
|
if (provider.name === "ollamaLocal") {
|
|
190
192
|
return provider.baseUrl.length > 0 && provider.model.length > 0;
|
|
191
193
|
}
|
|
194
|
+
if (provider.name === "ollamaCloud") {
|
|
195
|
+
return provider.apiKey.length > 0 && provider.baseUrl.length > 0;
|
|
196
|
+
}
|
|
192
197
|
return provider.apiKey.length > 0;
|
|
193
198
|
}
|
|
194
199
|
function getTelegramApprovedUsers(config) {
|
|
@@ -330,6 +335,13 @@ function migrateLegacyTelegramAccess(config) {
|
|
|
330
335
|
delete telegram.pairedUsername;
|
|
331
336
|
return config;
|
|
332
337
|
}
|
|
338
|
+
function migrateLegacyOllamaCloudBaseUrl(config) {
|
|
339
|
+
if (config.providers.ollamaCloud.baseUrl === "https://ollama.com/api") {
|
|
340
|
+
config.providers.ollamaCloud.baseUrl = "https://ollama.com/v1";
|
|
341
|
+
saveConfig(config);
|
|
342
|
+
}
|
|
343
|
+
return config;
|
|
344
|
+
}
|
|
333
345
|
|
|
334
346
|
// src/utils/logger.ts
|
|
335
347
|
import pino from "pino";
|
|
@@ -1531,7 +1543,7 @@ var OpenAICompatProvider = class extends BaseProvider {
|
|
|
1531
1543
|
model;
|
|
1532
1544
|
client;
|
|
1533
1545
|
modelInstance;
|
|
1534
|
-
constructor(config) {
|
|
1546
|
+
constructor(config, { useChatApi } = {}) {
|
|
1535
1547
|
super(config);
|
|
1536
1548
|
this.name = config.name;
|
|
1537
1549
|
this.model = config.model;
|
|
@@ -1539,7 +1551,7 @@ var OpenAICompatProvider = class extends BaseProvider {
|
|
|
1539
1551
|
apiKey: config.apiKey,
|
|
1540
1552
|
baseURL: config.baseUrl
|
|
1541
1553
|
});
|
|
1542
|
-
this.modelInstance = this.client(config.model);
|
|
1554
|
+
this.modelInstance = useChatApi ? this.client.chat(config.model) : this.client(config.model);
|
|
1543
1555
|
}
|
|
1544
1556
|
async generateText(prompt, systemPrompt) {
|
|
1545
1557
|
const result = await generateText({
|
|
@@ -1686,7 +1698,7 @@ var OllamaProvider = class extends BaseProvider {
|
|
|
1686
1698
|
if (this.name === "ollamaLocal") {
|
|
1687
1699
|
return this.config.baseUrl.length > 0 && this.config.model.length > 0;
|
|
1688
1700
|
}
|
|
1689
|
-
return this.config.apiKey.length > 0;
|
|
1701
|
+
return this.config.apiKey.length > 0 && this.config.baseUrl.length > 0;
|
|
1690
1702
|
}
|
|
1691
1703
|
getModelInstance() {
|
|
1692
1704
|
return this.modelInstance;
|
|
@@ -1748,8 +1760,10 @@ var ProviderRegistry = class {
|
|
|
1748
1760
|
provider = new AnthropicProvider(pc);
|
|
1749
1761
|
} else if (pc.name === "deepseek") {
|
|
1750
1762
|
provider = new DeepSeekProvider(pc);
|
|
1751
|
-
} else if (pc.name === "
|
|
1763
|
+
} else if (pc.name === "ollamaLocal") {
|
|
1752
1764
|
provider = new OllamaProvider(pc);
|
|
1765
|
+
} else if (pc.name === "ollamaCloud") {
|
|
1766
|
+
provider = new OpenAICompatProvider(pc, { useChatApi: true });
|
|
1753
1767
|
} else if (pc.name === "mimo" || pc.name === "mimoTokenPlan") {
|
|
1754
1768
|
provider = new MiMoProvider(pc);
|
|
1755
1769
|
} else {
|
|
@@ -8292,17 +8306,27 @@ async function fetchGrokModels(config) {
|
|
|
8292
8306
|
const ids = (data.data ?? []).filter((model) => model.output_modalities?.includes("text") || model.output_modalities == null).map((model) => model.id?.trim() ?? "").filter((id) => id.startsWith("grok-"));
|
|
8293
8307
|
return buildModelCatalog("grok", ids, config.model);
|
|
8294
8308
|
}
|
|
8295
|
-
async function
|
|
8296
|
-
const headers = config.apiKey ? { Authorization: `Bearer ${config.apiKey}` } : void 0;
|
|
8309
|
+
async function fetchOllamaCloudModels(config) {
|
|
8297
8310
|
const data = await fetchJson(
|
|
8298
|
-
`${trimTrailingSlash(config.baseUrl)}/
|
|
8311
|
+
`${trimTrailingSlash(config.baseUrl)}/models`,
|
|
8299
8312
|
{
|
|
8300
|
-
headers
|
|
8313
|
+
headers: {
|
|
8314
|
+
Authorization: `Bearer ${config.apiKey}`
|
|
8315
|
+
}
|
|
8301
8316
|
},
|
|
8302
|
-
|
|
8317
|
+
"Mercury could not fetch models for this Ollama Cloud key. Please re-enter it."
|
|
8318
|
+
);
|
|
8319
|
+
const ids = (data.data ?? []).map((model) => model.id?.trim() ?? "").filter(Boolean);
|
|
8320
|
+
return buildModelCatalog("ollamaCloud", ids, config.model);
|
|
8321
|
+
}
|
|
8322
|
+
async function fetchOllamaLocalModels(config) {
|
|
8323
|
+
const data = await fetchJson(
|
|
8324
|
+
`${trimTrailingSlash(config.baseUrl)}/tags`,
|
|
8325
|
+
{},
|
|
8326
|
+
"Mercury could not fetch models from this Ollama Local server. Please check the base URL and try again."
|
|
8303
8327
|
);
|
|
8304
8328
|
const ids = (data.models ?? []).map((model) => model.model?.trim() || model.name?.trim() || "").filter(Boolean);
|
|
8305
|
-
return buildModelCatalog(
|
|
8329
|
+
return buildModelCatalog("ollamaLocal", ids, config.model);
|
|
8306
8330
|
}
|
|
8307
8331
|
async function fetchMiMoModels(config) {
|
|
8308
8332
|
const data = await fetchJson(
|
|
@@ -8343,8 +8367,11 @@ async function fetchProviderModelCatalog(provider, config) {
|
|
|
8343
8367
|
if (provider === "grok") {
|
|
8344
8368
|
return fetchGrokModels(config);
|
|
8345
8369
|
}
|
|
8346
|
-
if (provider === "ollamaCloud"
|
|
8347
|
-
return
|
|
8370
|
+
if (provider === "ollamaCloud") {
|
|
8371
|
+
return fetchOllamaCloudModels(config);
|
|
8372
|
+
}
|
|
8373
|
+
if (provider === "ollamaLocal") {
|
|
8374
|
+
return fetchOllamaLocalModels(config);
|
|
8348
8375
|
}
|
|
8349
8376
|
if (provider === "mimo") {
|
|
8350
8377
|
return fetchMiMoModels(config);
|