easyrouter-config 1.0.6 → 1.0.7

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.
Files changed (2) hide show
  1. package/dist/index.js +62 -18
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -20,7 +20,7 @@ import { parseArgs } from "util";
20
20
  import pc from "picocolors";
21
21
 
22
22
  // src/config/constants.ts
23
- var VERSION = true ? "1.0.6" : "0.0.0-dev";
23
+ var VERSION = true ? "1.0.7" : "0.0.0-dev";
24
24
  var PRIMARY_HOST = "https://easyrouter.io";
25
25
  var FALLBACK_HOSTS = ["https://ezr.sh"];
26
26
  var HOST_PROBE_TIMEOUT_MS = 5e3;
@@ -362,6 +362,26 @@ var claudeClient = {
362
362
  // src/config/models.ts
363
363
  import { log as log2, select, isCancel } from "@clack/prompts";
364
364
  import pc4 from "picocolors";
365
+ function toOpenClawCost(m) {
366
+ const ratio = m.model_ratio ?? 0;
367
+ const compRatio = m.completion_ratio ?? 1;
368
+ const cacheRatio = m.cache_ratio ?? 0;
369
+ const input = round6(ratio * 2e-3);
370
+ const output = round6(ratio * compRatio * 2e-3);
371
+ const cacheRead = round6(ratio * cacheRatio * 2e-3);
372
+ const cacheWrite = round6(input * 1.25);
373
+ const tiered = m.tiered_pricing;
374
+ const contextWindow = tiered?.input?.threshold ?? tiered?.output?.threshold ?? tiered?.cache_read?.threshold ?? 131072;
375
+ const maxTokens = Math.min(32768, Math.max(4096, Math.floor(contextWindow / 4)));
376
+ return {
377
+ cost: { input, output, cacheRead, cacheWrite },
378
+ contextWindow,
379
+ maxTokens
380
+ };
381
+ }
382
+ function round6(n) {
383
+ return Math.round(n * 1e6) / 1e6;
384
+ }
365
385
  async function fetchEasyRouterModels(host, verbose) {
366
386
  const url = host.replace(/\/+$/, "") + "/api/pricing";
367
387
  try {
@@ -595,27 +615,48 @@ async function patchOpenClawJson(llms, defaultModel, ctx) {
595
615
  }
596
616
  return 1;
597
617
  }
598
- const existingIds = new Set(
599
- provider.models.map((m) => m.id)
600
- );
618
+ const existingById = /* @__PURE__ */ new Map();
619
+ provider.models.forEach((m, i) => {
620
+ existingById.set(m.id, i);
621
+ });
601
622
  const before = provider.models.length;
623
+ let updated = 0;
624
+ const agentsModels = json?.agents?.defaults?.models ?? null;
602
625
  for (const m of llms) {
603
- if (existingIds.has(m.model_name)) continue;
604
- provider.models.push({
605
- id: m.model_name,
606
- name: m.model_name + " (EasyRouter)",
607
- contextWindow: 16e3,
608
- // OpenClaw 默认值;用户可自行编辑
609
- maxTokens: 4096,
610
- input: ["text"],
611
- cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
612
- reasoning: false
613
- });
626
+ const { cost, contextWindow, maxTokens } = toOpenClawCost(m);
627
+ const idx = existingById.get(m.model_name);
628
+ if (idx !== void 0) {
629
+ const existing = provider.models[idx];
630
+ if (existing.cost?.input === 0 && existing.cost?.output === 0) {
631
+ existing.cost = cost;
632
+ existing.contextWindow = contextWindow;
633
+ existing.maxTokens = maxTokens;
634
+ updated++;
635
+ }
636
+ } else {
637
+ provider.models.push({
638
+ id: m.model_name,
639
+ name: m.model_name + " (EasyRouter)",
640
+ contextWindow,
641
+ maxTokens,
642
+ input: ["text"],
643
+ cost,
644
+ reasoning: false
645
+ });
646
+ }
647
+ if (agentsModels !== null) {
648
+ const agentKey = `${OPENCLAW_PROVIDER_ID}/${m.model_name}`;
649
+ const existing = agentsModels[agentKey];
650
+ if (!existing || Object.keys(existing).length === 0) {
651
+ agentsModels[agentKey] = { alias: agentKey };
652
+ }
653
+ }
614
654
  }
615
- if (provider.models.length === before) {
655
+ const added = provider.models.length - before;
656
+ if (added === 0 && updated === 0) {
616
657
  if (ctx.verbose) {
617
658
  console.warn(
618
- `[openclaw] \u5DF2\u6CE8\u518C\u8FC7\u6240\u6709 ${llms.length} \u4E2A\u6A21\u578B\uFF0C\u8DF3\u8FC7 patch`
659
+ `[openclaw] \u6240\u6709 ${llms.length} \u4E2A\u6A21\u578B\u5747\u5DF2\u662F\u6700\u65B0\uFF0C\u8DF3\u8FC7\u5199\u5165`
619
660
  );
620
661
  }
621
662
  return provider.models.length;
@@ -623,8 +664,11 @@ async function patchOpenClawJson(llms, defaultModel, ctx) {
623
664
  await fs.copyFile(configPath, configPath + ".bak." + Date.now());
624
665
  await atomicWriteJson(configPath, json);
625
666
  if (ctx.verbose) {
667
+ const parts = [];
668
+ if (added > 0) parts.push(`\u65B0\u589E ${added} \u4E2A`);
669
+ if (updated > 0) parts.push(`\u4FEE\u6B63 cost/ctx ${updated} \u4E2A`);
626
670
  console.warn(
627
- `[openclaw] \u2713 \u6CE8\u518C ${provider.models.length - before} \u4E2A\u65B0\u6A21\u578B\uFF0C\u5171 ${provider.models.length} \u4E2A\uFF08\u9ED8\u8BA4\uFF1A${defaultModel}\uFF09`
671
+ `[openclaw] \u2713 ${parts.join("\uFF0C")}\uFF0C\u5171 ${provider.models.length} \u4E2A\uFF08\u9ED8\u8BA4\uFF1A${defaultModel}\uFF09`
628
672
  );
629
673
  }
630
674
  return provider.models.length;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "easyrouter-config",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "🚀 一键把 EasyRouter 接入 Claude Code & Codex —— 粘贴 Key 即用",
5
5
  "type": "module",
6
6
  "bin": {