39 lines
832 B
TypeScript
39 lines
832 B
TypeScript
import { CLIENT_NAMES } from "./constants.js";
|
|
import type { ClientName } from "./types.js";
|
|
|
|
export interface DispatchConfig {
|
|
defaultClient?: ClientName;
|
|
client?: ClientName;
|
|
}
|
|
|
|
export function resolveClient(
|
|
prompt: string,
|
|
config?: DispatchConfig
|
|
): ClientName | null {
|
|
// Explicit --client flag takes highest precedence
|
|
if (config?.client && CLIENT_NAMES.includes(config.client)) {
|
|
return config.client;
|
|
}
|
|
|
|
const lower = prompt.toLowerCase();
|
|
|
|
// Check for "open code" before "opencode" to handle the spaced variant
|
|
if (lower.includes("open code")) {
|
|
return "opencode";
|
|
}
|
|
|
|
if (lower.includes("claude")) {
|
|
return "claude";
|
|
}
|
|
|
|
if (lower.includes("codex")) {
|
|
return "codex";
|
|
}
|
|
|
|
if (lower.includes("opencode")) {
|
|
return "opencode";
|
|
}
|
|
|
|
return config?.defaultClient ?? null;
|
|
}
|