MCPcopy Create free account
hub / github.com/CommonstackAI/UncommonRoute / register

Function register

openclaw-plugin/src/index.js:198–433  ·  view source on GitHub ↗
(api)

Source from the content-addressed store, hash-verified

196 version: VERSION,
197
198 register(api) {
199 const isDisabled =
200 process.env.UNCOMMON_ROUTE_DISABLED === "true" ||
201 process.env.UNCOMMON_ROUTE_DISABLED === "1";
202 if (isDisabled) {
203 api.logger.info("UncommonRoute disabled via UNCOMMON_ROUTE_DISABLED");
204 return;
205 }
206
207 const cfg = api.pluginConfig || {};
208 const port = cfg.port || Number(process.env.UNCOMMON_ROUTE_PORT) || DEFAULT_PORT;
209 const upstream = cfg.upstream || process.env.UNCOMMON_ROUTE_UPSTREAM || DEFAULT_UPSTREAM;
210 const baseUrl = `http://127.0.0.1:${port}/v1`;
211
212 if (!upstream) {
213 api.logger.warn("UncommonRoute: No upstream configured. Set UNCOMMON_ROUTE_UPSTREAM or configure 'upstream' in plugin config.");
214 api.logger.warn(" Example: UNCOMMON_ROUTE_UPSTREAM=https://api.commonstack.ai/v1 UNCOMMON_ROUTE_API_KEY=csk-...");
215 }
216
217 // 1. Register provider immediately (sync, models available right away)
218 api.registerProvider({
219 id: "uncommon-route",
220 label: "UncommonRoute",
221 docsPath: "https://github.com/CommonstackAI/UncommonRoute",
222 aliases: ["ur", "uncommon"],
223 envVars: [],
224 get models() { return buildModels(baseUrl); },
225 auth: [],
226 });
227
228 if (!api.config.models) api.config.models = { providers: {} };
229 if (!api.config.models.providers) api.config.models.providers = {};
230 api.config.models.providers["uncommon-route"] = buildModels(baseUrl);
231
232 api.logger.info(`UncommonRoute provider registered (${MODELS.length} models)`);
233
234 // 2. Register commands
235 api.registerCommand({
236 name: "route",
237 description: "Show which model UncommonRoute would pick for a prompt",
238 acceptsArgs: true,
239 requireAuth: false,
240 handler: async (ctx) => {
241 const prompt = (ctx.args || ctx.commandBody || "").trim();
242 if (!prompt) return { text: "Usage: /route <prompt>" };
243 try {
244 const resp = await fetch(`http://127.0.0.1:${port}/v1/chat/completions`, {
245 method: "POST",
246 headers: { "content-type": "application/json" },
247 body: JSON.stringify({ model: "uncommon-route/auto", messages: [{ role: "user", content: `/debug ${prompt}` }] }),
248 signal: AbortSignal.timeout(5000),
249 });
250 lastRequestId = resp.headers.get("x-uncommon-route-request-id");
251 lastTier = resp.headers.get("x-uncommon-route-tier");
252 const data = await resp.json();
253 let text = data?.choices?.[0]?.message?.content || "No response";
254 if (lastRequestId) {
255 text += `\n\n_Rate this: \`/feedback ok\` · \`/feedback weak\` · \`/feedback strong\`_`;

Callers

nothing calls this directly

Calls 9

buildModelsFunction · 0.85
fetchJsonFunction · 0.85
postJsonFunction · 0.85
applyLimitsFunction · 0.85
bootstrapFunction · 0.85
infoMethod · 0.80
stringifyMethod · 0.80
pushMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected