@ckcloudai.com/clawrouter 0.0.1 → 0.0.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
@@ -66,7 +66,9 @@ var USER_AGENT = `ckcloud/${VERSION}`;
66
66
 
67
67
  // src/models.ts
68
68
  var BASE_API_URL = "https://www.ckcloudai.com/api";
69
- var BASE_MODELS = [
69
+ var CKCLOUD_MODEL_API = "https://t.ckcloudai.com/v1/models";
70
+ var MODEL_FETCH_TIMEOUT_MS = 3e3;
71
+ var DEFAULT_BASE_MODELS = [
70
72
  // Smart routing meta-models — proxy replaces with actual model
71
73
  // NOTE: Model IDs are WITHOUT provider prefix (OpenClaw adds "ckcloud/" automatically)
72
74
  {
@@ -78,6 +80,53 @@ var BASE_MODELS = [
78
80
  maxOutput: 128e3
79
81
  }
80
82
  ];
83
+ function mapCkcloudModel(raw) {
84
+ const id = typeof raw.model === "string" ? raw.model.trim() : "";
85
+ if (!id) return null;
86
+ const contextLength = Number(raw.contextLength ?? 0);
87
+ const normalizedContext = Number.isFinite(contextLength) && contextLength > 0 ? contextLength : 4096;
88
+ const inputPrice = Number(raw.inputPrice ?? 0);
89
+ const outputPrice = Number(raw.outputPrice ?? 0);
90
+ return {
91
+ id,
92
+ name: typeof raw.displayName === "string" && raw.displayName.trim() ? raw.displayName.trim() : id,
93
+ inputPrice: Number.isFinite(inputPrice) ? inputPrice : 0,
94
+ outputPrice: Number.isFinite(outputPrice) ? outputPrice : 0,
95
+ contextWindow: normalizedContext,
96
+ maxOutput: Math.min(128e3, normalizedContext),
97
+ toolCalling: Boolean(raw.supportFunction)
98
+ };
99
+ }
100
+ function mergeBaseModels(apiModels) {
101
+ const merged = [...DEFAULT_BASE_MODELS];
102
+ const seen = new Set(merged.map((m) => m.id));
103
+ for (const m of apiModels) {
104
+ if (seen.has(m.id)) continue;
105
+ merged.push(m);
106
+ seen.add(m.id);
107
+ }
108
+ return merged;
109
+ }
110
+ async function loadBaseModels() {
111
+ const controller = new AbortController();
112
+ const timeout = setTimeout(() => controller.abort(), MODEL_FETCH_TIMEOUT_MS);
113
+ try {
114
+ const res = await fetch(CKCLOUD_MODEL_API, { signal: controller.signal });
115
+ if (!res.ok) {
116
+ return DEFAULT_BASE_MODELS;
117
+ }
118
+ const body = await res.json();
119
+ if (!Array.isArray(body)) return DEFAULT_BASE_MODELS;
120
+ const mapped = body.map(mapCkcloudModel).filter((m) => m !== null);
121
+ if (mapped.length === 0) return DEFAULT_BASE_MODELS;
122
+ return mergeBaseModels(mapped);
123
+ } catch {
124
+ return DEFAULT_BASE_MODELS;
125
+ } finally {
126
+ clearTimeout(timeout);
127
+ }
128
+ }
129
+ var BASE_MODELS = await loadBaseModels();
81
130
  function resolveModelAlias(model) {
82
131
  const normalized = model.trim().toLowerCase();
83
132
  const resolved = MODEL_ALIASES[normalized];
@@ -176,14 +225,16 @@ var MODEL_ALIASES = {
176
225
  // Note: auto, free, eco, premium are virtual routing profiles registered in BASE_MODELS
177
226
  // They don't need aliases since they're already top-level model IDs
178
227
  };
179
- var ALIAS_MODELS = Object.entries(MODEL_ALIASES).map(([alias, targetId]) => {
180
- const target = BASE_MODELS.find((m) => m.id === targetId);
181
- if (!target) return null;
182
- return toOpenClawModel({ ...target, id: alias, name: `${alias} \u2192 ${target.name}` });
183
- }).filter((m) => m !== null);
228
+ function buildAliasModels(baseModels) {
229
+ return Object.entries(MODEL_ALIASES).map(([alias, targetId]) => {
230
+ const target = baseModels.find((m) => m.id === targetId);
231
+ if (!target) return null;
232
+ return toOpenClawModel({ ...target, id: alias, name: `${alias} \u2192 ${target.name}` });
233
+ }).filter((m) => m !== null);
234
+ }
184
235
  var OPENCLAW_MODELS = [
185
236
  ...BASE_MODELS.map(toOpenClawModel),
186
- ...ALIAS_MODELS
237
+ ...buildAliasModels(BASE_MODELS)
187
238
  ];
188
239
  function buildProviderModels(baseUrl) {
189
240
  if (!baseUrl) {
@@ -3955,8 +4006,8 @@ ${lines.join("\n")}`;
3955
4006
  };
3956
4007
 
3957
4008
  // src/proxy.ts
3958
- var CKCLOUD_API = "https://test.holmesai.ucloud.com.cn:5173/x402";
3959
- var CKCLOUD_SOLANA_API = "https://test.holmesai.ucloud.com.cn:5173/x402";
4009
+ var CKCLOUD_API = "https://t.ckcloudai.com/x402";
4010
+ var CKCLOUD_SOLANA_API = "https://https://t.ckcloudai.com/x402";
3960
4011
  var IMAGE_DIR = join5(homedir4(), ".openclaw", "ckcloud", "images");
3961
4012
  var AUTO_MODEL = "ckcloud/auto";
3962
4013
  var BALANCE_CHECK_BUFFER = 1.5;