Revert "Merge pull request 'fix: use systemPrompt instead of prependContext for end marker instruction' (#5) from fix/moderator-and-system-prompt into feat/turn-based-speaking"
This reverts commit6a81f75fd0, reversing changes made to86fdc63802.
This commit is contained in:
@@ -22,8 +22,7 @@
|
|||||||
"debugLogChannelIds": [],
|
"debugLogChannelIds": [],
|
||||||
"discordControlApiBaseUrl": "http://127.0.0.1:8790",
|
"discordControlApiBaseUrl": "http://127.0.0.1:8790",
|
||||||
"discordControlApiToken": "<DISCORD_CONTROL_AUTH_TOKEN>",
|
"discordControlApiToken": "<DISCORD_CONTROL_AUTH_TOKEN>",
|
||||||
"discordControlCallerId": "agent-main",
|
"discordControlCallerId": "agent-main"
|
||||||
"moderatorBotToken": "<MODERATOR_BOT_TOKEN>"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ type DebugConfig = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const sessionDecision = new Map<string, DecisionRecord>();
|
const sessionDecision = new Map<string, DecisionRecord>();
|
||||||
const sessionInjected = new Set<string>(); // Track which sessions have already injected the end marker
|
|
||||||
const MAX_SESSION_DECISIONS = 2000;
|
const MAX_SESSION_DECISIONS = 2000;
|
||||||
const DECISION_TTL_MS = 5 * 60 * 1000;
|
const DECISION_TTL_MS = 5 * 60 * 1000;
|
||||||
function buildEndMarkerInstruction(endSymbols: string[], isGroupChat: boolean): string {
|
function buildEndMarkerInstruction(endSymbols: string[], isGroupChat: boolean): string {
|
||||||
@@ -262,20 +261,8 @@ function resolveDiscordUserId(api: OpenClawPluginApi, accountId: string): string
|
|||||||
const discord = (channels.discord as Record<string, unknown>) || {};
|
const discord = (channels.discord as Record<string, unknown>) || {};
|
||||||
const accounts = (discord.accounts as Record<string, Record<string, unknown>>) || {};
|
const accounts = (discord.accounts as Record<string, Record<string, unknown>>) || {};
|
||||||
const acct = accounts[accountId];
|
const acct = accounts[accountId];
|
||||||
|
if (!acct?.token || typeof acct.token !== "string") return undefined;
|
||||||
if (!acct?.token || typeof acct.token !== "string") {
|
return userIdFromToken(acct.token);
|
||||||
api.logger.warn(`whispergate: resolveDiscordUserId failed for accountId=${accountId}: no token found in config`);
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
const userId = userIdFromToken(acct.token);
|
|
||||||
if (!userId) {
|
|
||||||
api.logger.warn(`whispergate: resolveDiscordUserId failed for accountId=${accountId}: could not parse userId from token`);
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
api.logger.info(`whispergate: resolveDiscordUserId success accountId=${accountId} userId=${userId}`);
|
|
||||||
return userId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get the moderator bot's Discord user ID from its token */
|
/** Get the moderator bot's Discord user ID from its token */
|
||||||
@@ -624,27 +611,7 @@ export default {
|
|||||||
// This ensures only the current speaker can respond even for human messages.
|
// This ensures only the current speaker can respond even for human messages.
|
||||||
if (derived.channelId) {
|
if (derived.channelId) {
|
||||||
ensureTurnOrder(api, derived.channelId);
|
ensureTurnOrder(api, derived.channelId);
|
||||||
|
const accountId = resolveAccountId(api, ctx.agentId || "");
|
||||||
// Try resolveAccountId first, fall back to ctx.accountId if not found
|
|
||||||
let accountId = resolveAccountId(api, ctx.agentId || "");
|
|
||||||
|
|
||||||
// Debug log for turn check
|
|
||||||
if (shouldDebugLog(live, derived.channelId)) {
|
|
||||||
const turnDebug = getTurnDebugInfo(derived.channelId);
|
|
||||||
api.logger.info(
|
|
||||||
`whispergate: turn check preflight agentId=${ctx.agentId ?? "undefined"} ` +
|
|
||||||
`resolvedAccountId=${accountId ?? "undefined"} ` +
|
|
||||||
`ctxAccountId=${ctx.accountId ?? "undefined"} ` +
|
|
||||||
`turnOrderLen=${turnDebug.turnOrder?.length ?? 0} ` +
|
|
||||||
`currentSpeaker=${turnDebug.currentSpeaker ?? "null"}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback to ctx.accountId if resolveAccountId failed
|
|
||||||
if (!accountId && ctx.accountId) {
|
|
||||||
accountId = String(ctx.accountId);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (accountId) {
|
if (accountId) {
|
||||||
const turnCheck = checkTurn(derived.channelId, accountId);
|
const turnCheck = checkTurn(derived.channelId, accountId);
|
||||||
if (!turnCheck.allowed) {
|
if (!turnCheck.allowed) {
|
||||||
@@ -736,17 +703,6 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sessionDecision.delete(key);
|
sessionDecision.delete(key);
|
||||||
|
|
||||||
// Only inject once per session (one-time injection)
|
|
||||||
if (sessionInjected.has(key)) {
|
|
||||||
if (shouldDebugLog(live, undefined)) {
|
|
||||||
api.logger.info(
|
|
||||||
`whispergate: debug before_prompt_build session=${key} inject skipped (already injected)`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!rec.decision.shouldInjectEndMarkerPrompt) {
|
if (!rec.decision.shouldInjectEndMarkerPrompt) {
|
||||||
if (shouldDebugLog(live, undefined)) {
|
if (shouldDebugLog(live, undefined)) {
|
||||||
api.logger.info(
|
api.logger.info(
|
||||||
@@ -770,10 +726,7 @@ export default {
|
|||||||
if (idStr) identity = idStr + "\n\n";
|
if (idStr) identity = idStr + "\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark session as injected (one-time injection)
|
api.logger.info(`whispergate: prepend end marker instruction for session=${key}, reason=${rec.decision.reason} isGroupChat=${isGroupChat}`);
|
||||||
sessionInjected.add(key);
|
|
||||||
|
|
||||||
api.logger.info(`whispergate: one-time inject end marker for session=${key}, reason=${rec.decision.reason} isGroupChat=${isGroupChat}`);
|
|
||||||
return { prependContext: identity + instruction };
|
return { prependContext: identity + instruction };
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user