Use pluginConfig directly for Dirigent runtime config
This commit is contained in:
@@ -10,7 +10,6 @@ import { registerBeforeMessageWriteHook } from "./hooks/before-message-write.js"
|
||||
import { registerMessageSentHook } from "./hooks/message-sent.js";
|
||||
import { registerDirigentCommand } from "./commands/dirigent-command.js";
|
||||
import { registerDirigentTools } from "./tools/register-tools.js";
|
||||
import { getLivePluginConfig } from "./core/live-config.js";
|
||||
import { ensurePolicyStateLoaded, persistPolicies, policyState } from "./policy/store.js";
|
||||
import { buildAgentIdentity, buildUserIdToAccountIdMap, resolveAccountId } from "./core/identity.js";
|
||||
import { extractMentionedUserIds, getModeratorUserId } from "./core/mentions.js";
|
||||
@@ -34,6 +33,24 @@ type DebugConfig = {
|
||||
debugLogChannelIds?: string[];
|
||||
};
|
||||
|
||||
type NormalizedDirigentConfig = DirigentConfig & {
|
||||
enableDiscordControlTool: boolean;
|
||||
enableDirigentPolicyTool: boolean;
|
||||
};
|
||||
|
||||
function normalizePluginConfig(api: OpenClawPluginApi): NormalizedDirigentConfig {
|
||||
return {
|
||||
enableDiscordControlTool: true,
|
||||
enableDirigentPolicyTool: true,
|
||||
enableDebugLogs: false,
|
||||
debugLogChannelIds: [],
|
||||
noReplyPort: 8787,
|
||||
schedulingIdentifier: "➡️",
|
||||
waitIdentifier: "👤",
|
||||
...(api.pluginConfig || {}),
|
||||
} as NormalizedDirigentConfig;
|
||||
}
|
||||
|
||||
function buildEndMarkerInstruction(endSymbols: string[], isGroupChat: boolean, schedulingIdentifier: string, waitIdentifier: string): string {
|
||||
const symbols = endSymbols.length > 0 ? endSymbols.join("") : "🔚";
|
||||
let instruction = `Your response MUST end with ${symbols}. Exception: gateway keywords (e.g. NO_REPLY, HEARTBEAT_OK, NO, or an empty response) must NOT include ${symbols}.`;
|
||||
@@ -52,21 +69,8 @@ export default {
|
||||
id: "dirigent",
|
||||
name: "Dirigent",
|
||||
register(api: OpenClawPluginApi) {
|
||||
// Merge pluginConfig with defaults (in case config is missing from openclaw.json)
|
||||
const baseConfig = {
|
||||
enableDiscordControlTool: true,
|
||||
enableDirigentPolicyTool: true,
|
||||
schedulingIdentifier: "➡️",
|
||||
waitIdentifier: "👤",
|
||||
noReplyPort: 8787,
|
||||
...(api.pluginConfig || {}),
|
||||
} as DirigentConfig & {
|
||||
enableDiscordControlTool: boolean;
|
||||
enableDirigentPolicyTool: boolean;
|
||||
};
|
||||
|
||||
const liveAtRegister = getLivePluginConfig(api, baseConfig as DirigentConfig);
|
||||
ensurePolicyStateLoaded(api, liveAtRegister);
|
||||
const baseConfig = normalizePluginConfig(api);
|
||||
ensurePolicyStateLoaded(api, baseConfig);
|
||||
|
||||
// Resolve plugin directory for locating sibling modules (no-reply-api/)
|
||||
// Note: api.resolvePath(".") returns cwd, not script directory. Use import.meta.url instead.
|
||||
@@ -77,7 +81,7 @@ export default {
|
||||
api.on("gateway_start", () => {
|
||||
api.logger.info(`dirigent: gateway_start event received`);
|
||||
|
||||
const live = getLivePluginConfig(api, baseConfig as DirigentConfig);
|
||||
const live = normalizePluginConfig(api);
|
||||
|
||||
// Check no-reply-api server file exists
|
||||
const serverPath = path.resolve(pluginDir, "no-reply-api", "server.mjs");
|
||||
@@ -112,9 +116,8 @@ export default {
|
||||
// Register tools
|
||||
registerDirigentTools({
|
||||
api,
|
||||
baseConfig: baseConfig as DirigentConfig,
|
||||
baseConfig,
|
||||
pickDefined,
|
||||
getLivePluginConfig,
|
||||
});
|
||||
|
||||
// Turn management is handled internally by the plugin (not exposed as tools).
|
||||
@@ -122,8 +125,7 @@ export default {
|
||||
|
||||
registerMessageReceivedHook({
|
||||
api,
|
||||
baseConfig: baseConfig as DirigentConfig,
|
||||
getLivePluginConfig,
|
||||
baseConfig,
|
||||
shouldDebugLog,
|
||||
debugCtxSummary,
|
||||
ensureTurnOrder,
|
||||
@@ -135,7 +137,7 @@ export default {
|
||||
|
||||
registerBeforeModelResolveHook({
|
||||
api,
|
||||
baseConfig: baseConfig as DirigentConfig,
|
||||
baseConfig,
|
||||
sessionDecision,
|
||||
sessionAllowed,
|
||||
sessionChannelId,
|
||||
@@ -143,7 +145,6 @@ export default {
|
||||
policyState,
|
||||
DECISION_TTL_MS,
|
||||
ensurePolicyStateLoaded,
|
||||
getLivePluginConfig,
|
||||
resolveAccountId,
|
||||
pruneDecisionMap,
|
||||
shouldDebugLog,
|
||||
@@ -152,13 +153,12 @@ export default {
|
||||
|
||||
registerBeforePromptBuildHook({
|
||||
api,
|
||||
baseConfig: baseConfig as DirigentConfig,
|
||||
baseConfig,
|
||||
sessionDecision,
|
||||
sessionInjected,
|
||||
policyState,
|
||||
DECISION_TTL_MS,
|
||||
ensurePolicyStateLoaded,
|
||||
getLivePluginConfig,
|
||||
shouldDebugLog,
|
||||
buildEndMarkerInstruction,
|
||||
buildSchedulingIdentifierInstruction,
|
||||
@@ -168,24 +168,22 @@ export default {
|
||||
// Register slash commands for Discord
|
||||
registerDirigentCommand({
|
||||
api,
|
||||
baseConfig: baseConfig as DirigentConfig,
|
||||
baseConfig,
|
||||
policyState,
|
||||
persistPolicies,
|
||||
ensurePolicyStateLoaded,
|
||||
getLivePluginConfig,
|
||||
});
|
||||
|
||||
// Handle NO_REPLY detection before message write
|
||||
registerBeforeMessageWriteHook({
|
||||
api,
|
||||
baseConfig: baseConfig as DirigentConfig,
|
||||
baseConfig,
|
||||
policyState,
|
||||
sessionAllowed,
|
||||
sessionChannelId,
|
||||
sessionAccountId,
|
||||
sessionTurnHandled,
|
||||
ensurePolicyStateLoaded,
|
||||
getLivePluginConfig,
|
||||
shouldDebugLog,
|
||||
ensureTurnOrder,
|
||||
resolveDiscordUserId,
|
||||
@@ -195,13 +193,12 @@ export default {
|
||||
// Turn advance: when an agent sends a message, check if it signals end of turn
|
||||
registerMessageSentHook({
|
||||
api,
|
||||
baseConfig: baseConfig as DirigentConfig,
|
||||
baseConfig,
|
||||
policyState,
|
||||
sessionChannelId,
|
||||
sessionAccountId,
|
||||
sessionTurnHandled,
|
||||
ensurePolicyStateLoaded,
|
||||
getLivePluginConfig,
|
||||
resolveDiscordUserId,
|
||||
sendModeratorMessage,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user