-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
38 lines (31 loc) · 1.26 KB
/
Copy pathindex.ts
File metadata and controls
38 lines (31 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import type { OpenClawPluginApi } from "openclaw/plugin-sdk/core";
import { resolveSmartRoute } from "./src/router.js";
import type { SmartRoutingConfig } from "./src/types.js";
export default function register(api: OpenClawPluginApi) {
const config = api.pluginConfig as SmartRoutingConfig;
if (!config?.enabled) {
api.logger.info("Smart routing disabled");
return;
}
api.logger.info(`Smart routing enabled (classifier: ${config.classifier ?? "heuristic"})`);
api.on("before_model_resolve", async (event, ctx) => {
// Skip routing for heartbeat and cron triggers — these have their own model configs.
if (ctx.trigger === "heartbeat" || ctx.trigger === "cron") return;
const result = await resolveSmartRoute({
prompt: event.prompt,
routingConfig: config,
});
if (!result) return;
api.logger.info(
`[smart-routing] tier=${result.tier} ` +
`model=${result.providerOverride}/${result.modelOverride} ` +
`confidence=${result.classification.confidence.toFixed(2)} ` +
`classifier=${result.classification.classifier} ` +
`reason="${result.classification.reason}"`,
);
return {
modelOverride: result.modelOverride,
providerOverride: result.providerOverride,
};
});
}