60 lines
2.0 KiB
TypeScript
60 lines
2.0 KiB
TypeScript
import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
|
|
import { advanceTurn, getTurnDebugInfo, resetTurn } from "../turn-manager.js";
|
|
|
|
type CommandDeps = {
|
|
api: OpenClawPluginApi;
|
|
policyState: { channelPolicies: Record<string, unknown> };
|
|
};
|
|
|
|
export function registerDirigentCommand(deps: CommandDeps): void {
|
|
const { api, policyState } = deps;
|
|
|
|
api.registerCommand({
|
|
name: "dirigent",
|
|
description: "Dirigent channel policy management",
|
|
acceptsArgs: true,
|
|
handler: async (cmdCtx) => {
|
|
const args = cmdCtx.args || "";
|
|
const parts = args.trim().split(/\s+/);
|
|
const subCmd = parts[0] || "help";
|
|
|
|
if (subCmd === "help") {
|
|
return {
|
|
text:
|
|
`Dirigent commands:\n` +
|
|
`/dirigent status - Show current channel status\n` +
|
|
`/dirigent turn-status - Show turn-based speaking status\n` +
|
|
`/dirigent turn-advance - Manually advance turn\n` +
|
|
`/dirigent turn-reset - Reset turn order`,
|
|
};
|
|
}
|
|
|
|
if (subCmd === "status") {
|
|
return { text: JSON.stringify({ policies: policyState.channelPolicies }, null, 2) };
|
|
}
|
|
|
|
if (subCmd === "turn-status") {
|
|
const channelId = cmdCtx.channelId;
|
|
if (!channelId) return { text: "Cannot get channel ID", isError: true };
|
|
return { text: JSON.stringify(getTurnDebugInfo(channelId), null, 2) };
|
|
}
|
|
|
|
if (subCmd === "turn-advance") {
|
|
const channelId = cmdCtx.channelId;
|
|
if (!channelId) return { text: "Cannot get channel ID", isError: true };
|
|
const next = advanceTurn(channelId);
|
|
return { text: JSON.stringify({ ok: true, nextSpeaker: next }) };
|
|
}
|
|
|
|
if (subCmd === "turn-reset") {
|
|
const channelId = cmdCtx.channelId;
|
|
if (!channelId) return { text: "Cannot get channel ID", isError: true };
|
|
resetTurn(channelId);
|
|
return { text: JSON.stringify({ ok: true }) };
|
|
}
|
|
|
|
return { text: `Unknown subcommand: ${subCmd}`, isError: true };
|
|
},
|
|
});
|
|
}
|