@ckcloudai.com/clawrouter 0.0.1 → 0.0.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 +88 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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
|
|
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 = [...DEFAULT_BASE_MODELS];
|
|
81
130
|
function resolveModelAlias(model) {
|
|
82
131
|
const normalized = model.trim().toLowerCase();
|
|
83
132
|
const resolved = MODEL_ALIASES[normalized];
|
|
@@ -176,15 +225,34 @@ 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
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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
|
-
...
|
|
237
|
+
...buildAliasModels(BASE_MODELS)
|
|
187
238
|
];
|
|
239
|
+
var baseModelsInit = null;
|
|
240
|
+
function rebuildModels(nextBaseModels) {
|
|
241
|
+
BASE_MODELS = nextBaseModels;
|
|
242
|
+
OPENCLAW_MODELS = [
|
|
243
|
+
...BASE_MODELS.map(toOpenClawModel),
|
|
244
|
+
...buildAliasModels(BASE_MODELS)
|
|
245
|
+
];
|
|
246
|
+
}
|
|
247
|
+
function initBaseModels() {
|
|
248
|
+
if (baseModelsInit) return baseModelsInit;
|
|
249
|
+
baseModelsInit = (async () => {
|
|
250
|
+
const next = await loadBaseModels();
|
|
251
|
+
rebuildModels(next);
|
|
252
|
+
})();
|
|
253
|
+
return baseModelsInit;
|
|
254
|
+
}
|
|
255
|
+
void initBaseModels();
|
|
188
256
|
function buildProviderModels(baseUrl) {
|
|
189
257
|
if (!baseUrl) {
|
|
190
258
|
baseUrl = BASE_API_URL;
|
|
@@ -3955,8 +4023,8 @@ ${lines.join("\n")}`;
|
|
|
3955
4023
|
};
|
|
3956
4024
|
|
|
3957
4025
|
// src/proxy.ts
|
|
3958
|
-
var CKCLOUD_API = "https://
|
|
3959
|
-
var CKCLOUD_SOLANA_API = "https://
|
|
4026
|
+
var CKCLOUD_API = "https://t.ckcloudai.com/x402";
|
|
4027
|
+
var CKCLOUD_SOLANA_API = "https://https://t.ckcloudai.com/x402";
|
|
3960
4028
|
var IMAGE_DIR = join5(homedir4(), ".openclaw", "ckcloud", "images");
|
|
3961
4029
|
var AUTO_MODEL = "ckcloud/auto";
|
|
3962
4030
|
var BALANCE_CHECK_BUFFER = 1.5;
|
|
@@ -4584,6 +4652,7 @@ async function startProxy(options) {
|
|
|
4584
4652
|
const walletKey = typeof options.wallet === "string" ? options.wallet : options.wallet.key;
|
|
4585
4653
|
const solanaPrivateKeyBytes = typeof options.wallet === "string" ? void 0 : options.wallet.solanaPrivateKeyBytes;
|
|
4586
4654
|
setPluginLogger(options.logger ?? console);
|
|
4655
|
+
await initBaseModels();
|
|
4587
4656
|
const paymentChain = options.paymentChain ?? await resolvePaymentChain();
|
|
4588
4657
|
const apiBase = options.apiBase ?? (paymentChain === "solana" && solanaPrivateKeyBytes ? CKCLOUD_SOLANA_API : CKCLOUD_API);
|
|
4589
4658
|
if (paymentChain === "solana" && !solanaPrivateKeyBytes) {
|
|
@@ -6198,6 +6267,16 @@ var plugin = {
|
|
|
6198
6267
|
models: OPENCLAW_MODELS
|
|
6199
6268
|
};
|
|
6200
6269
|
api.logger.info("ckcloud provider registered");
|
|
6270
|
+
initBaseModels().then(() => {
|
|
6271
|
+
injectModelsConfig(api.logger);
|
|
6272
|
+
if (api.config.models?.providers?.ckcloud) {
|
|
6273
|
+
api.config.models.providers.ckcloud.models = OPENCLAW_MODELS;
|
|
6274
|
+
}
|
|
6275
|
+
}).catch((err) => {
|
|
6276
|
+
api.logger.warn(
|
|
6277
|
+
`Failed to refresh models list: ${err instanceof Error ? err.message : String(err)}`
|
|
6278
|
+
);
|
|
6279
|
+
});
|
|
6201
6280
|
createStatsCommand().then((statsCommand) => {
|
|
6202
6281
|
api.registerCommand(statsCommand);
|
|
6203
6282
|
}).catch((err) => {
|