Skip to content

Commit 57d1579

Browse files
committed
refactor: extract createExcludeCommand to src/commands/exclude.ts (v0.12.131)
1 parent ca56ad3 commit 57d1579

File tree

4 files changed

+100
-95
lines changed

4 files changed

+100
-95
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@blockrun/clawrouter",
3-
"version": "0.12.130",
3+
"version": "0.12.131",
44
"description": "Smart LLM router — save 85% on inference costs. 55+ models (11 free), one wallet, x402 micropayments.",
55
"type": "module",
66
"main": "dist/index.js",

src/commands/exclude.ts

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/**
2+
* /exclude command — manage excluded models.
3+
* Extracted from index.ts for modularity.
4+
*/
5+
import type { OpenClawPluginCommandDefinition, PluginCommandContext } from "../types.js";
6+
import {
7+
loadExcludeList,
8+
addExclusion,
9+
removeExclusion,
10+
clearExclusions,
11+
} from "../exclude-models.js";
12+
13+
export function createExcludeCommand(): OpenClawPluginCommandDefinition {
14+
return {
15+
name: "exclude",
16+
description: "Manage excluded models — /exclude add|remove|clear <model>",
17+
acceptsArgs: true,
18+
requireAuth: true,
19+
handler: async (ctx: PluginCommandContext) => {
20+
const args = ctx.args?.trim() || "";
21+
const parts = args.split(/\s+/);
22+
const subcommand = parts[0]?.toLowerCase() || "";
23+
const modelArg = parts.slice(1).join(" ").trim();
24+
25+
// /exclude (no args) — show current list
26+
if (!subcommand) {
27+
const list = loadExcludeList();
28+
if (list.size === 0) {
29+
return {
30+
text: "No models excluded.\n\nUsage:\n /exclude add <model> — block a model\n /exclude remove <model> — unblock\n /exclude clear — remove all",
31+
};
32+
}
33+
const models = [...list]
34+
.sort()
35+
.map((m) => ` • ${m}`)
36+
.join("\n");
37+
return {
38+
text: `Excluded models (${list.size}):\n${models}\n\nUse /exclude remove <model> to unblock.`,
39+
};
40+
}
41+
42+
// /exclude add <model>
43+
if (subcommand === "add") {
44+
if (!modelArg) {
45+
return {
46+
text: "Usage: /exclude add <model>\nExample: /exclude add nvidia/gpt-oss-120b",
47+
isError: true,
48+
};
49+
}
50+
const resolved = addExclusion(modelArg);
51+
const list = loadExcludeList();
52+
return {
53+
text: `Excluded: ${resolved}\n\nActive exclusions (${list.size}):\n${[...list]
54+
.sort()
55+
.map((m) => ` • ${m}`)
56+
.join("\n")}`,
57+
};
58+
}
59+
60+
// /exclude remove <model>
61+
if (subcommand === "remove") {
62+
if (!modelArg) {
63+
return { text: "Usage: /exclude remove <model>", isError: true };
64+
}
65+
const removed = removeExclusion(modelArg);
66+
if (!removed) {
67+
return { text: `Model "${modelArg}" was not in the exclude list.` };
68+
}
69+
const list = loadExcludeList();
70+
return {
71+
text: `Unblocked: ${modelArg}\n\nActive exclusions (${list.size}):\n${
72+
list.size > 0
73+
? [...list]
74+
.sort()
75+
.map((m) => ` • ${m}`)
76+
.join("\n")
77+
: " (none)"
78+
}`,
79+
};
80+
}
81+
82+
// /exclude clear
83+
if (subcommand === "clear") {
84+
clearExclusions();
85+
return { text: "All model exclusions cleared." };
86+
}
87+
88+
return {
89+
text: `Unknown subcommand: ${subcommand}\n\nUsage:\n /exclude — show list\n /exclude add <model>\n /exclude remove <model>\n /exclude clear`,
90+
isError: true,
91+
};
92+
},
93+
};
94+
}

src/index.ts

Lines changed: 3 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,7 @@ import {
4040
import type { WalletResolution } from "./auth.js";
4141
import type { RoutingConfig } from "./router/index.js";
4242
import { BalanceMonitor } from "./balance.js";
43-
import {
44-
loadExcludeList,
45-
addExclusion,
46-
removeExclusion,
47-
clearExclusions,
48-
} from "./exclude-models.js";
43+
import { loadExcludeList } from "./exclude-models.js";
4944

5045
/**
5146
* Wait for proxy health check to pass (quick check, not RPC).
@@ -83,6 +78,7 @@ import { privateKeyToAccount } from "viem/accounts";
8378
import { getStats } from "./stats.js";
8479
import { buildPartnerTools, PARTNER_SERVICES } from "./partners/index.js";
8580
import { createStatsCommand } from "./commands/stats.js";
81+
import { createExcludeCommand } from "./commands/exclude.js";
8682

8783
/**
8884
* Install ClawRouter skills into OpenClaw's workspace skills directory.
@@ -676,92 +672,7 @@ async function startProxyInBackground(api: OpenClawPluginApi): Promise<void> {
676672

677673
// createStatsCommand moved to src/commands/stats.ts
678674

679-
/**
680-
* /exclude command handler for ClawRouter.
681-
* Manages excluded models — /exclude add|remove|clear <model>
682-
*/
683-
function createExcludeCommand(): OpenClawPluginCommandDefinition {
684-
return {
685-
name: "exclude",
686-
description: "Manage excluded models — /exclude add|remove|clear <model>",
687-
acceptsArgs: true,
688-
requireAuth: true,
689-
handler: async (ctx: PluginCommandContext) => {
690-
const args = ctx.args?.trim() || "";
691-
const parts = args.split(/\s+/);
692-
const subcommand = parts[0]?.toLowerCase() || "";
693-
const modelArg = parts.slice(1).join(" ").trim();
694-
695-
// /exclude (no args) — show current list
696-
if (!subcommand) {
697-
const list = loadExcludeList();
698-
if (list.size === 0) {
699-
return {
700-
text: "No models excluded.\n\nUsage:\n /exclude add <model> — block a model\n /exclude remove <model> — unblock\n /exclude clear — remove all",
701-
};
702-
}
703-
const models = [...list]
704-
.sort()
705-
.map((m) => ` • ${m}`)
706-
.join("\n");
707-
return {
708-
text: `Excluded models (${list.size}):\n${models}\n\nUse /exclude remove <model> to unblock.`,
709-
};
710-
}
711-
712-
// /exclude add <model>
713-
if (subcommand === "add") {
714-
if (!modelArg) {
715-
return {
716-
text: "Usage: /exclude add <model>\nExample: /exclude add nvidia/gpt-oss-120b",
717-
isError: true,
718-
};
719-
}
720-
const resolved = addExclusion(modelArg);
721-
const list = loadExcludeList();
722-
return {
723-
text: `Excluded: ${resolved}\n\nActive exclusions (${list.size}):\n${[...list]
724-
.sort()
725-
.map((m) => ` • ${m}`)
726-
.join("\n")}`,
727-
};
728-
}
729-
730-
// /exclude remove <model>
731-
if (subcommand === "remove") {
732-
if (!modelArg) {
733-
return { text: "Usage: /exclude remove <model>", isError: true };
734-
}
735-
const removed = removeExclusion(modelArg);
736-
if (!removed) {
737-
return { text: `Model "${modelArg}" was not in the exclude list.` };
738-
}
739-
const list = loadExcludeList();
740-
return {
741-
text: `Unblocked: ${modelArg}\n\nActive exclusions (${list.size}):\n${
742-
list.size > 0
743-
? [...list]
744-
.sort()
745-
.map((m) => ` • ${m}`)
746-
.join("\n")
747-
: " (none)"
748-
}`,
749-
};
750-
}
751-
752-
// /exclude clear
753-
if (subcommand === "clear") {
754-
clearExclusions();
755-
return { text: "All model exclusions cleared." };
756-
}
757-
758-
return {
759-
text: `Unknown subcommand: ${subcommand}\n\nUsage:\n /exclude — show list\n /exclude add <model>\n /exclude remove <model>\n /exclude clear`,
760-
isError: true,
761-
};
762-
},
763-
};
764-
}
675+
// createExcludeCommand moved to src/commands/exclude.ts
765676

766677
/**
767678
* /wallet command handler for ClawRouter.

0 commit comments

Comments
 (0)