@ckcloudai.com/clawrouter 0.0.7 → 0.0.8

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
@@ -2221,6 +2221,12 @@ function getFallbackChainFiltered(tier, tierConfigs, estimatedTotalTokens, getCo
2221
2221
  }
2222
2222
 
2223
2223
  // src/router/config.ts
2224
+ var PLACEHOLDER_TIER_CONFIG = () => ({
2225
+ SIMPLE: { primary: "auto", fallback: [] },
2226
+ MEDIUM: { primary: "auto", fallback: [] },
2227
+ COMPLEX: { primary: "auto", fallback: [] },
2228
+ REASONING: { primary: "auto", fallback: [] }
2229
+ });
2224
2230
  var DEFAULT_ROUTING_CONFIG = {
2225
2231
  version: "2.0",
2226
2232
  classifier: {
@@ -3246,291 +3252,11 @@ var DEFAULT_ROUTING_CONFIG = {
3246
3252
  // Below this confidence → ambiguous (null tier)
3247
3253
  confidenceThreshold: 0.7
3248
3254
  },
3249
- // Auto (balanced) tier configs - current default smart routing
3250
- tiers: {
3251
- SIMPLE: {
3252
- primary: "moonshot/kimi-k2.5",
3253
- // $0.60 / $3.00
3254
- fallback: [
3255
- "openai/gpt-5-nano",
3256
- // $0.05 / $0.40
3257
- "gpt-4.1-nano",
3258
- // $0.10 / $0.40
3259
- "gemini-2.5-flash",
3260
- // $0.10 / $0.40
3261
- "gpt-4o-mini",
3262
- // $0.15 / $0.60
3263
- "openai/gpt-5-mini",
3264
- // $0.25 / $2.00
3265
- "deepseek-ai/DeepSeek-V3.2",
3266
- // $0.28 / $0.42
3267
- "MiniMax-M2.5",
3268
- // $0.30 / $1.20
3269
- "gemini-2.5-flash"
3270
- // $0.30 / $2.50
3271
- ]
3272
- },
3273
- MEDIUM: {
3274
- primary: "gpt-4.1-mini",
3275
- // $0.40 / $1.60
3276
- fallback: [
3277
- "zai-org/glm-5",
3278
- // $1.00 / $3.20
3279
- "glm-5-turbo",
3280
- // $1.20 / $4.00
3281
- "openai/gpt-4.1",
3282
- // $2.00 / $8.00
3283
- "o3-2025-04-16",
3284
- // $2.00 / $8.00
3285
- "gemini-3-pro-preview",
3286
- // $2.00 / $12.00
3287
- "gemini-3.1-pro-preview"
3288
- // $2.00 / $12.00
3289
- ]
3290
- },
3291
- COMPLEX: {
3292
- primary: "gpt-5.4",
3293
- // $2.50 / $15.00
3294
- fallback: [
3295
- "openai/gpt-5.2",
3296
- // $1.75 / $14.00
3297
- "gpt-5.3-codex",
3298
- // $1.75 / $14.00
3299
- "openai/gpt-4o",
3300
- // $2.50 / $10.00
3301
- "claude-sonnet-4-6",
3302
- // $3.00 / $15.00
3303
- "claude-opus-4-5-20251101",
3304
- // $5.00 / $25.00
3305
- "claude-opus-4-6"
3306
- // $5.00 / $25.00
3307
- ]
3308
- },
3309
- REASONING: {
3310
- primary: "o4-mini",
3311
- // $1.10 / $4.40
3312
- fallback: [
3313
- "o1",
3314
- // $15.00 / $60.00
3315
- "gpt-5.2-pro"
3316
- // $21.00 / $168.00
3317
- ]
3318
- }
3319
- },
3320
- // Eco tier configs - absolute cheapest (ckcloud/eco)
3321
- ecoTiers: {
3322
- SIMPLE: {
3323
- primary: "moonshot/kimi-k2.5",
3324
- // $0.60 / $3.00
3325
- fallback: [
3326
- "openai/gpt-5-nano",
3327
- // $0.05 / $0.40
3328
- "gpt-4.1-nano",
3329
- // $0.10 / $0.40
3330
- "gemini-2.5-flash",
3331
- // $0.10 / $0.40
3332
- "gpt-4o-mini",
3333
- // $0.15 / $0.60
3334
- "openai/gpt-5-mini",
3335
- // $0.25 / $2.00
3336
- "deepseek-ai/DeepSeek-V3.2",
3337
- // $0.28 / $0.42
3338
- "MiniMax-M2.5",
3339
- // $0.30 / $1.20
3340
- "gemini-2.5-flash"
3341
- // $0.30 / $2.50
3342
- ]
3343
- },
3344
- MEDIUM: {
3345
- primary: "gpt-4.1-mini",
3346
- // $0.40 / $1.60
3347
- fallback: [
3348
- "zai-org/glm-5",
3349
- // $1.00 / $3.20
3350
- "glm-5-turbo",
3351
- // $1.20 / $4.00
3352
- "openai/gpt-4.1",
3353
- // $2.00 / $8.00
3354
- "o3-2025-04-16",
3355
- // $2.00 / $8.00
3356
- "gemini-3-pro-preview",
3357
- // $2.00 / $12.00
3358
- "gemini-3.1-pro-preview"
3359
- // $2.00 / $12.00
3360
- ]
3361
- },
3362
- COMPLEX: {
3363
- primary: "gpt-5.4",
3364
- // $2.50 / $15.00
3365
- fallback: [
3366
- "openai/gpt-5.2",
3367
- // $1.75 / $14.00
3368
- "gpt-5.3-codex",
3369
- // $1.75 / $14.00
3370
- "openai/gpt-4o",
3371
- // $2.50 / $10.00
3372
- "claude-sonnet-4-6",
3373
- // $3.00 / $15.00
3374
- "claude-opus-4-5-20251101",
3375
- // $5.00 / $25.00
3376
- "claude-opus-4-6"
3377
- // $5.00 / $25.00
3378
- ]
3379
- },
3380
- REASONING: {
3381
- primary: "o4-mini",
3382
- // $1.10 / $4.40
3383
- fallback: [
3384
- "o1",
3385
- // $15.00 / $60.00
3386
- "gpt-5.2-pro"
3387
- // $21.00 / $168.00
3388
- ]
3389
- }
3390
- },
3391
- // Premium tier configs - best quality (ckcloud/premium)
3392
- // codex=complex coding, kimi=simple coding, sonnet=reasoning/instructions, opus=architecture/PM/audits
3393
- premiumTiers: {
3394
- SIMPLE: {
3395
- primary: "moonshot/kimi-k2.5",
3396
- // $0.60 / $3.00
3397
- fallback: [
3398
- "openai/gpt-5-nano",
3399
- // $0.05 / $0.40
3400
- "gpt-4.1-nano",
3401
- // $0.10 / $0.40
3402
- "gemini-2.5-flash",
3403
- // $0.10 / $0.40
3404
- "gpt-4o-mini",
3405
- // $0.15 / $0.60
3406
- "openai/gpt-5-mini",
3407
- // $0.25 / $2.00
3408
- "deepseek-ai/DeepSeek-V3.2",
3409
- // $0.28 / $0.42
3410
- "MiniMax-M2.5",
3411
- // $0.30 / $1.20
3412
- "gemini-2.5-flash"
3413
- // $0.30 / $2.50
3414
- ]
3415
- },
3416
- MEDIUM: {
3417
- primary: "gpt-4.1-mini",
3418
- // $0.40 / $1.60
3419
- fallback: [
3420
- "zai-org/glm-5",
3421
- // $1.00 / $3.20
3422
- "glm-5-turbo",
3423
- // $1.20 / $4.00
3424
- "openai/gpt-4.1",
3425
- // $2.00 / $8.00
3426
- "o3-2025-04-16",
3427
- // $2.00 / $8.00
3428
- "gemini-3-pro-preview",
3429
- // $2.00 / $12.00
3430
- "gemini-3.1-pro-preview"
3431
- // $2.00 / $12.00
3432
- ]
3433
- },
3434
- COMPLEX: {
3435
- primary: "gpt-5.4",
3436
- // $2.50 / $15.00
3437
- fallback: [
3438
- "openai/gpt-5.2",
3439
- // $1.75 / $14.00
3440
- "gpt-5.3-codex",
3441
- // $1.75 / $14.00
3442
- "openai/gpt-4o",
3443
- // $2.50 / $10.00
3444
- "claude-sonnet-4-6",
3445
- // $3.00 / $15.00
3446
- "claude-opus-4-5-20251101",
3447
- // $5.00 / $25.00
3448
- "claude-opus-4-6"
3449
- // $5.00 / $25.00
3450
- ]
3451
- },
3452
- REASONING: {
3453
- primary: "o4-mini",
3454
- // $1.10 / $4.40
3455
- fallback: [
3456
- "o1",
3457
- // $15.00 / $60.00
3458
- "gpt-5.2-pro"
3459
- // $21.00 / $168.00
3460
- ]
3461
- }
3462
- },
3463
- // Agentic tier configs - models that excel at multi-step autonomous tasks
3464
- agenticTiers: {
3465
- SIMPLE: {
3466
- primary: "moonshot/kimi-k2.5",
3467
- // $0.60 / $3.00
3468
- fallback: [
3469
- "openai/gpt-5-nano",
3470
- // $0.05 / $0.40
3471
- "gpt-4.1-nano",
3472
- // $0.10 / $0.40
3473
- "gemini-2.5-flash",
3474
- // $0.10 / $0.40
3475
- "gpt-4o-mini",
3476
- // $0.15 / $0.60
3477
- "openai/gpt-5-mini",
3478
- // $0.25 / $2.00
3479
- "deepseek-ai/DeepSeek-V3.2",
3480
- // $0.28 / $0.42
3481
- "MiniMax-M2.5",
3482
- // $0.30 / $1.20
3483
- "gemini-2.5-flash"
3484
- // $0.30 / $2.50
3485
- ]
3486
- },
3487
- MEDIUM: {
3488
- primary: "gpt-4.1-mini",
3489
- // $0.40 / $1.60
3490
- fallback: [
3491
- "zai-org/glm-5",
3492
- // $1.00 / $3.20
3493
- "glm-5-turbo",
3494
- // $1.20 / $4.00
3495
- "openai/gpt-4.1",
3496
- // $2.00 / $8.00
3497
- "o3-2025-04-16",
3498
- // $2.00 / $8.00
3499
- "gemini-3-pro-preview",
3500
- // $2.00 / $12.00
3501
- "gemini-3.1-pro-preview"
3502
- // $2.00 / $12.00
3503
- ]
3504
- },
3505
- COMPLEX: {
3506
- primary: "gpt-5.4",
3507
- // $2.50 / $15.00
3508
- fallback: [
3509
- "openai/gpt-5.2",
3510
- // $1.75 / $14.00
3511
- "gpt-5.3-codex",
3512
- // $1.75 / $14.00
3513
- "openai/gpt-4o",
3514
- // $2.50 / $10.00
3515
- "claude-sonnet-4-6",
3516
- // $3.00 / $15.00
3517
- "claude-opus-4-5-20251101",
3518
- // $5.00 / $25.00
3519
- "claude-opus-4-6"
3520
- // $5.00 / $25.00
3521
- ]
3522
- },
3523
- REASONING: {
3524
- primary: "o4-mini",
3525
- // $1.10 / $4.40
3526
- fallback: [
3527
- "o1",
3528
- // $15.00 / $60.00
3529
- "gpt-5.2-pro"
3530
- // $21.00 / $168.00
3531
- ]
3532
- }
3533
- },
3255
+ // Tier configs are populated at runtime based on initBaseModels().
3256
+ tiers: PLACEHOLDER_TIER_CONFIG(),
3257
+ ecoTiers: PLACEHOLDER_TIER_CONFIG(),
3258
+ premiumTiers: PLACEHOLDER_TIER_CONFIG(),
3259
+ agenticTiers: PLACEHOLDER_TIER_CONFIG(),
3534
3260
  overrides: {
3535
3261
  maxTokensForceComplex: 1e5,
3536
3262
  structuredOutputMinTier: "MEDIUM",
@@ -4875,6 +4601,7 @@ var CKCLOUD_API = "https://t.ckcloudai.com/x402";
4875
4601
  var CKCLOUD_SOLANA_API = "https://https://t.ckcloudai.com/x402";
4876
4602
  var IMAGE_DIR = join5(homedir4(), ".openclaw", "ckcloud", "images");
4877
4603
  var AUTO_MODEL = "ckcloud/auto";
4604
+ var BASE_AUTO_MODEL_ID = "auto";
4878
4605
  var BALANCE_CHECK_BUFFER = 1.5;
4879
4606
  var ROUTING_PROFILES = /* @__PURE__ */ new Set([
4880
4607
  "ckcloud/eco",
@@ -5359,11 +5086,72 @@ async function checkExistingProxy(port) {
5359
5086
  function buildModelPricing() {
5360
5087
  const map = /* @__PURE__ */ new Map();
5361
5088
  for (const m of BASE_MODELS) {
5362
- if (m.id === AUTO_MODEL) continue;
5089
+ if (m.id === AUTO_MODEL || m.id === BASE_AUTO_MODEL_ID) continue;
5363
5090
  map.set(m.id, { inputPrice: m.inputPrice, outputPrice: m.outputPrice });
5364
5091
  }
5365
5092
  return map;
5366
5093
  }
5094
+ function buildTierConfigFromModels(candidates, fallbackPool) {
5095
+ const sorted = [...candidates].sort((a, b) => {
5096
+ const priceDelta = a.outputPrice - b.outputPrice;
5097
+ if (priceDelta !== 0) return priceDelta;
5098
+ return a.id.localeCompare(b.id);
5099
+ });
5100
+ const pool = sorted.length > 0 ? sorted : fallbackPool;
5101
+ const primary = pool[0];
5102
+ if (!primary) {
5103
+ return { primary: BASE_AUTO_MODEL_ID, fallback: [] };
5104
+ }
5105
+ return {
5106
+ primary: primary.id,
5107
+ fallback: pool.slice(1).map((m) => m.id)
5108
+ };
5109
+ }
5110
+ function buildTierConfigsFromBaseModels() {
5111
+ const available = BASE_MODELS.filter((m) => m.id !== BASE_AUTO_MODEL_ID);
5112
+ const sortedAll = [...available].sort((a, b) => {
5113
+ const priceDelta = a.outputPrice - b.outputPrice;
5114
+ if (priceDelta !== 0) return priceDelta;
5115
+ return a.id.localeCompare(b.id);
5116
+ });
5117
+ const fallbackPool = sortedAll.length > 0 ? sortedAll : available;
5118
+ const matchesThink = (name) => typeof name === "string" && name.toLowerCase().includes("think");
5119
+ const reasoningModels = available.filter((m) => matchesThink(m.id) || matchesThink(m.name));
5120
+ const reasoningTier = buildTierConfigFromModels(reasoningModels, fallbackPool);
5121
+ const inRange = (price, min, max, includeMax) => {
5122
+ if (!Number.isFinite(price)) return false;
5123
+ if (includeMax) return price >= min && price <= max;
5124
+ return price >= min && price < max;
5125
+ };
5126
+ const selectByRange = (min, max, includeMax) => buildTierConfigFromModels(
5127
+ available.filter((m) => inRange(m.outputPrice, min, max, includeMax)),
5128
+ fallbackPool
5129
+ );
5130
+ const tiers = {
5131
+ SIMPLE: selectByRange(0, 1.5, false),
5132
+ MEDIUM: selectByRange(1.5, 3, false),
5133
+ COMPLEX: selectByRange(3, 100, true),
5134
+ REASONING: reasoningTier
5135
+ };
5136
+ const ecoTiers = {
5137
+ SIMPLE: selectByRange(0, 1, false),
5138
+ MEDIUM: selectByRange(1, 2, false),
5139
+ COMPLEX: selectByRange(2, 3, true),
5140
+ REASONING: reasoningTier
5141
+ };
5142
+ const premiumTiers = {
5143
+ SIMPLE: selectByRange(1, 3, false),
5144
+ MEDIUM: selectByRange(3, 10, false),
5145
+ COMPLEX: selectByRange(10, 100, true),
5146
+ REASONING: reasoningTier
5147
+ };
5148
+ return {
5149
+ tiers,
5150
+ ecoTiers,
5151
+ premiumTiers,
5152
+ agenticTiers: tiers
5153
+ };
5154
+ }
5367
5155
  function buildProxyModelList(createdAt = Math.floor(Date.now() / 1e3)) {
5368
5156
  const seen = /* @__PURE__ */ new Set();
5369
5157
  return OPENCLAW_MODELS.filter((model) => {
@@ -5385,6 +5173,9 @@ function mergeRoutingConfig(overrides) {
5385
5173
  classifier: { ...DEFAULT_ROUTING_CONFIG.classifier, ...overrides.classifier },
5386
5174
  scoring: { ...DEFAULT_ROUTING_CONFIG.scoring, ...overrides.scoring },
5387
5175
  tiers: { ...DEFAULT_ROUTING_CONFIG.tiers, ...overrides.tiers },
5176
+ ecoTiers: { ...DEFAULT_ROUTING_CONFIG.ecoTiers, ...overrides.ecoTiers },
5177
+ premiumTiers: { ...DEFAULT_ROUTING_CONFIG.premiumTiers, ...overrides.premiumTiers },
5178
+ agenticTiers: { ...DEFAULT_ROUTING_CONFIG.agenticTiers, ...overrides.agenticTiers },
5388
5179
  overrides: { ...DEFAULT_ROUTING_CONFIG.overrides, ...overrides.overrides }
5389
5180
  };
5390
5181
  }
@@ -5498,6 +5289,11 @@ async function startProxy(options) {
5498
5289
  const solanaPrivateKeyBytes = typeof options.wallet === "string" ? void 0 : options.wallet.solanaPrivateKeyBytes;
5499
5290
  setPluginLogger(options.logger ?? console);
5500
5291
  await initBaseModels();
5292
+ const tierConfigs = buildTierConfigsFromBaseModels();
5293
+ DEFAULT_ROUTING_CONFIG.tiers = tierConfigs.tiers;
5294
+ DEFAULT_ROUTING_CONFIG.ecoTiers = tierConfigs.ecoTiers;
5295
+ DEFAULT_ROUTING_CONFIG.premiumTiers = tierConfigs.premiumTiers;
5296
+ DEFAULT_ROUTING_CONFIG.agenticTiers = tierConfigs.agenticTiers;
5501
5297
  const paymentChain = options.paymentChain ?? await resolvePaymentChain();
5502
5298
  logger.info(`paymentChain: ${paymentChain}`);
5503
5299
  const apiBase = options.apiBase ?? (paymentChain === "solana" && solanaPrivateKeyBytes ? CKCLOUD_SOLANA_API : CKCLOUD_API);