@cosmicstack/mercury-agent 1.1.1 → 1.1.2

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 CHANGED
@@ -90,6 +90,20 @@ function getDefaultConfig() {
90
90
  baseUrl: getEnv("OLLAMA_LOCAL_BASE_URL", "http://127.0.0.1:11434/api"),
91
91
  model: getEnv("OLLAMA_LOCAL_MODEL", "gpt-oss:20b"),
92
92
  enabled: getEnvBool("OLLAMA_LOCAL_ENABLED", false)
93
+ },
94
+ mimo: {
95
+ name: "mimo",
96
+ apiKey: getEnv("MIMO_API_KEY", ""),
97
+ baseUrl: getEnv("MIMO_BASE_URL", "https://api.xiaomimimo.com/v1"),
98
+ model: getEnv("MIMO_MODEL", "mimo-v2.5-pro"),
99
+ enabled: getEnvBool("MIMO_ENABLED", true)
100
+ },
101
+ mimoTokenPlan: {
102
+ name: "mimoTokenPlan",
103
+ apiKey: getEnv("MIMO_TOKEN_PLAN_API_KEY", ""),
104
+ baseUrl: getEnv("MIMO_TOKEN_PLAN_BASE_URL", "https://token-plan-cn.xiaomimimo.com/v1"),
105
+ model: getEnv("MIMO_TOKEN_PLAN_MODEL", "mimo-v2.5-pro"),
106
+ enabled: getEnvBool("MIMO_TOKEN_PLAN_ENABLED", false)
93
107
  }
94
108
  },
95
109
  channels: {
@@ -1679,6 +1693,36 @@ var OllamaProvider = class extends BaseProvider {
1679
1693
  }
1680
1694
  };
1681
1695
 
1696
+ // src/providers/mimo.ts
1697
+ import { createOpenAI as createOpenAI2 } from "@ai-sdk/openai";
1698
+ var MiMoProvider = class extends BaseProvider {
1699
+ name;
1700
+ model;
1701
+ modelInstance;
1702
+ constructor(config) {
1703
+ super(config);
1704
+ this.name = config.name;
1705
+ this.model = config.model;
1706
+ const client = createOpenAI2({
1707
+ apiKey: config.apiKey,
1708
+ baseURL: config.baseUrl
1709
+ });
1710
+ this.modelInstance = client.chat(config.model);
1711
+ }
1712
+ async generateText(_prompt, _systemPrompt) {
1713
+ throw new Error("Use getModelInstance() with the AI SDK agent loop");
1714
+ }
1715
+ async *streamText(_prompt, _systemPrompt) {
1716
+ throw new Error("Use getModelInstance() with the AI SDK agent loop");
1717
+ }
1718
+ isAvailable() {
1719
+ return this.config.apiKey.length > 0;
1720
+ }
1721
+ getModelInstance() {
1722
+ return this.modelInstance;
1723
+ }
1724
+ };
1725
+
1682
1726
  // src/providers/registry.ts
1683
1727
  var ProviderRegistry = class {
1684
1728
  providers = /* @__PURE__ */ new Map();
@@ -1692,7 +1736,9 @@ var ProviderRegistry = class {
1692
1736
  config.providers.anthropic,
1693
1737
  config.providers.grok,
1694
1738
  config.providers.ollamaCloud,
1695
- config.providers.ollamaLocal
1739
+ config.providers.ollamaLocal,
1740
+ config.providers.mimo,
1741
+ config.providers.mimoTokenPlan
1696
1742
  ];
1697
1743
  for (const pc of entries) {
1698
1744
  if (!isProviderConfigured(pc)) continue;
@@ -1704,6 +1750,8 @@ var ProviderRegistry = class {
1704
1750
  provider = new DeepSeekProvider(pc);
1705
1751
  } else if (pc.name === "ollamaCloud" || pc.name === "ollamaLocal") {
1706
1752
  provider = new OllamaProvider(pc);
1753
+ } else if (pc.name === "mimo" || pc.name === "mimoTokenPlan") {
1754
+ provider = new MiMoProvider(pc);
1707
1755
  } else {
1708
1756
  provider = new OpenAICompatProvider(pc);
1709
1757
  }
@@ -8100,6 +8148,14 @@ var OLLAMA_LOCAL_PREFERRED_MODELS = [
8100
8148
  "gpt-oss:20b",
8101
8149
  "gpt-oss:120b"
8102
8150
  ];
8151
+ var MIMO_PREFERRED_MODELS = [
8152
+ "mimo-v2.5-pro",
8153
+ "mimo-v2.5",
8154
+ "mimo-v2-pro",
8155
+ "mimo-v2-omni",
8156
+ "mimo-v2-flash"
8157
+ ];
8158
+ var MIMO_TOKEN_PLAN_PREFERRED_MODELS = MIMO_PREFERRED_MODELS;
8103
8159
  var ProviderModelFetchError = class extends Error {
8104
8160
  constructor(message) {
8105
8161
  super(message);
@@ -8154,7 +8210,9 @@ function chooseRecommendedModel(provider, models, currentModel) {
8154
8210
  anthropic: ANTHROPIC_PREFERRED_MODELS,
8155
8211
  grok: GROK_PREFERRED_MODELS,
8156
8212
  ollamaCloud: OLLAMA_CLOUD_PREFERRED_MODELS,
8157
- ollamaLocal: OLLAMA_LOCAL_PREFERRED_MODELS
8213
+ ollamaLocal: OLLAMA_LOCAL_PREFERRED_MODELS,
8214
+ mimo: MIMO_PREFERRED_MODELS,
8215
+ mimoTokenPlan: MIMO_TOKEN_PLAN_PREFERRED_MODELS
8158
8216
  };
8159
8217
  for (const candidate of preferredByProvider[provider]) {
8160
8218
  if (models.includes(candidate)) {
@@ -8178,7 +8236,9 @@ function buildModelCatalog(provider, models, currentModel) {
8178
8236
  anthropic: ANTHROPIC_PREFERRED_MODELS,
8179
8237
  grok: GROK_PREFERRED_MODELS,
8180
8238
  ollamaCloud: OLLAMA_CLOUD_PREFERRED_MODELS,
8181
- ollamaLocal: OLLAMA_LOCAL_PREFERRED_MODELS
8239
+ ollamaLocal: OLLAMA_LOCAL_PREFERRED_MODELS,
8240
+ mimo: MIMO_PREFERRED_MODELS,
8241
+ mimoTokenPlan: MIMO_TOKEN_PLAN_PREFERRED_MODELS
8182
8242
  };
8183
8243
  const withoutRecommended = filtered.filter((model) => model !== recommendedModel);
8184
8244
  const prioritized = prioritizeModels(withoutRecommended, preferredByProvider[provider]);
@@ -8244,6 +8304,38 @@ async function fetchOllamaModels(provider, config) {
8244
8304
  const ids = (data.models ?? []).map((model) => model.model?.trim() || model.name?.trim() || "").filter(Boolean);
8245
8305
  return buildModelCatalog(provider, ids, config.model);
8246
8306
  }
8307
+ async function fetchMiMoModels(config) {
8308
+ const data = await fetchJson(
8309
+ `${trimTrailingSlash(config.baseUrl)}/models`,
8310
+ {
8311
+ headers: {
8312
+ Authorization: `Bearer ${config.apiKey}`
8313
+ }
8314
+ },
8315
+ "Mercury could not fetch models for this MiMo key. Please re-enter it."
8316
+ );
8317
+ const ids = (data.data ?? []).map((model) => model.id?.trim() ?? "").filter((id) => {
8318
+ const lower = id.toLowerCase();
8319
+ return lower.startsWith("mimo-") && !lower.includes("tts");
8320
+ });
8321
+ return buildModelCatalog("mimo", ids, config.model);
8322
+ }
8323
+ async function fetchMiMoTokenPlanModels(config) {
8324
+ const data = await fetchJson(
8325
+ `${trimTrailingSlash(config.baseUrl)}/models`,
8326
+ {
8327
+ headers: {
8328
+ Authorization: `Bearer ${config.apiKey}`
8329
+ }
8330
+ },
8331
+ "Mercury could not fetch models for this MiMo Token Plan key. Please re-enter it."
8332
+ );
8333
+ const ids = (data.data ?? []).map((model) => model.id?.trim() ?? "").filter((id) => {
8334
+ const lower = id.toLowerCase();
8335
+ return lower.startsWith("mimo-") && !lower.includes("tts");
8336
+ });
8337
+ return buildModelCatalog("mimoTokenPlan", ids, config.model);
8338
+ }
8247
8339
  async function fetchProviderModelCatalog(provider, config) {
8248
8340
  if (provider === "anthropic") {
8249
8341
  return fetchAnthropicModels(config);
@@ -8254,6 +8346,12 @@ async function fetchProviderModelCatalog(provider, config) {
8254
8346
  if (provider === "ollamaCloud" || provider === "ollamaLocal") {
8255
8347
  return fetchOllamaModels(provider, config);
8256
8348
  }
8349
+ if (provider === "mimo") {
8350
+ return fetchMiMoModels(config);
8351
+ }
8352
+ if (provider === "mimoTokenPlan") {
8353
+ return fetchMiMoTokenPlanModels(config);
8354
+ }
8257
8355
  return fetchOpenAICompatModels(provider, config);
8258
8356
  }
8259
8357
 
@@ -8311,7 +8409,9 @@ var PROVIDER_OPTIONS = [
8311
8409
  { key: "anthropic", label: "Anthropic" },
8312
8410
  { key: "grok", label: "Grok (xAI)" },
8313
8411
  { key: "ollamaCloud", label: "Ollama Cloud" },
8314
- { key: "ollamaLocal", label: "Ollama Local" }
8412
+ { key: "ollamaLocal", label: "Ollama Local" },
8413
+ { key: "mimo", label: "MiMo (Xiaomi)" },
8414
+ { key: "mimoTokenPlan", label: "MiMo Token Plan (Xiaomi)" }
8315
8415
  ];
8316
8416
  function getConfiguredProviderNames(config) {
8317
8417
  return PROVIDER_OPTIONS.map((option) => option.key).filter((key) => isProviderConfigured(config.providers[key]));
@@ -8412,6 +8512,12 @@ function validateApiKey(provider, value) {
8412
8512
  if (provider === "ollamaCloud") {
8413
8513
  return looksLikeToken(value) ? null : "Ollama Cloud keys must look like a real API token: long, no spaces, and not plain text.";
8414
8514
  }
8515
+ if (provider === "mimo") {
8516
+ return /^sk-[A-Za-z0-9_-]{16,}$/i.test(value) ? null : "MiMo keys must start with `sk-`.";
8517
+ }
8518
+ if (provider === "mimoTokenPlan") {
8519
+ return /^tp-[A-Za-z0-9_-]{16,}$/i.test(value) ? null : "MiMo Token Plan keys must start with `tp-`.";
8520
+ }
8415
8521
  return null;
8416
8522
  }
8417
8523
  function validateBaseUrl(value) {
@@ -8760,6 +8866,38 @@ async function configure(existingConfig) {
8760
8866
  config.providers.ollamaLocal.model = result.model;
8761
8867
  config.providers.ollamaLocal.enabled = true;
8762
8868
  }
8869
+ continue;
8870
+ }
8871
+ if (provider === "mimo") {
8872
+ const mask = isReconfig && config.providers.mimo.apiKey ? ` [${maskKey(config.providers.mimo.apiKey)}]` : "";
8873
+ const result = await promptApiKeyWithModelSelection(
8874
+ config,
8875
+ "mimo",
8876
+ "MiMo",
8877
+ chalk7.white(` MiMo API key${mask}${isReconfig ? "" : " (Enter to skip)"}: `),
8878
+ isReconfig
8879
+ );
8880
+ if (!result.skipped && result.apiKey && result.model) {
8881
+ config.providers.mimo.apiKey = result.apiKey;
8882
+ config.providers.mimo.model = result.model;
8883
+ config.providers.mimo.enabled = true;
8884
+ }
8885
+ continue;
8886
+ }
8887
+ if (provider === "mimoTokenPlan") {
8888
+ const mask = isReconfig && config.providers.mimoTokenPlan.apiKey ? ` [${maskKey(config.providers.mimoTokenPlan.apiKey)}]` : "";
8889
+ const result = await promptApiKeyWithModelSelection(
8890
+ config,
8891
+ "mimoTokenPlan",
8892
+ "MiMo Token Plan",
8893
+ chalk7.white(` MiMo Token Plan API key${mask}${isReconfig ? "" : " (Enter to skip)"}: `),
8894
+ isReconfig
8895
+ );
8896
+ if (!result.skipped && result.apiKey && result.model) {
8897
+ config.providers.mimoTokenPlan.apiKey = result.apiKey;
8898
+ config.providers.mimoTokenPlan.model = result.model;
8899
+ config.providers.mimoTokenPlan.enabled = true;
8900
+ }
8763
8901
  }
8764
8902
  }
8765
8903
  const configuredProviders = getConfiguredProviderNames(config);