refactor: extract reply-end config constants / 抽出 reply-end 共用設定常數

This commit is contained in:
Alice (OpenClaw)
2026-05-13 14:21:43 +08:00
parent 56aabb28eb
commit abde0c243f
2 changed files with 33 additions and 10 deletions

24
src/config.ts Normal file
View File

@@ -0,0 +1,24 @@
import type { ReplyEndChoice } from "./types.js"
export const REPLY_END_CALLBACKS = {
continue: "rec:continue",
stop: "rec:stop",
} as const
export const REPLY_END_LABELS = {
continue: "A. 繼續",
stop: "B. 就這樣吧,不需要額外處理",
} as const
export const REPLY_END_RESOLVED_LABELS = {
continue: "✅ A. 繼續",
stop: "⏹ B. 就這樣吧,不需要額外處理",
} as const
export function buildReplyEndAckText(choice: ReplyEndChoice): string {
return choice === "continue"
? "reply-end-controls: continue received"
: "reply-end-controls: stop received"
}
export const STOP_POLICY_TEXT = "[System: The user previously pressed reply-end-controls Stop for this conversation. Treat the previous thread as closed. Unless the user's new message contains a clear new instruction or explicit request for more work, you must NOT proactively continue, must NOT add extra checks, must NOT propose next steps, must NOT extend the task, and should answer briefly and close cleanly.]"

View File

@@ -1,30 +1,29 @@
import type { ReplyEndChoice, ReplyEndState, TelegramInlineButton } from "../types.js" import type { ReplyEndChoice, ReplyEndState, TelegramInlineButton } from "../types.js"
import { REPLY_END_CALLBACKS, REPLY_END_LABELS, REPLY_END_RESOLVED_LABELS, STOP_POLICY_TEXT, buildReplyEndAckText } from "../config.js"
export function buildDefaultReplyEndButtons(): TelegramInlineButton[][] { export function buildDefaultReplyEndButtons(): TelegramInlineButton[][] {
return [[ return [[
{ text: "A. 繼續", callback_data: "rec:continue" }, { text: REPLY_END_LABELS.continue, callback_data: REPLY_END_CALLBACKS.continue },
{ text: "B. 就這樣吧,不需要額外處理", callback_data: "rec:stop" }, { text: REPLY_END_LABELS.stop, callback_data: REPLY_END_CALLBACKS.stop },
]] ]]
} }
export function buildResolvedReplyEndButtons(choice: ReplyEndChoice): TelegramInlineButton[][] { export function buildResolvedReplyEndButtons(choice: ReplyEndChoice): TelegramInlineButton[][] {
if (choice === "continue") { if (choice === "continue") {
return [[ return [[
{ text: "✅ A. 繼續", callback_data: "rec:continue" }, { text: REPLY_END_RESOLVED_LABELS.continue, callback_data: REPLY_END_CALLBACKS.continue },
{ text: "B. 就這樣吧,不需要額外處理", callback_data: "rec:stop" }, { text: REPLY_END_LABELS.stop, callback_data: REPLY_END_CALLBACKS.stop },
]] ]]
} }
return [[ return [[
{ text: "A. 繼續", callback_data: "rec:continue" }, { text: REPLY_END_LABELS.continue, callback_data: REPLY_END_CALLBACKS.continue },
{ text: "⏹ B. 就這樣吧,不需要額外處理", callback_data: "rec:stop" }, { text: REPLY_END_RESOLVED_LABELS.stop, callback_data: REPLY_END_CALLBACKS.stop },
]] ]]
} }
export function buildReplyEndAcknowledgement(choice: ReplyEndChoice): string { export function buildReplyEndAcknowledgement(choice: ReplyEndChoice): string {
return choice === "continue" return buildReplyEndAckText(choice)
? "reply-end-controls: continue received"
: "reply-end-controls: stop received"
} }
export function applyStopStateToInboundText(text: string, state: ReplyEndState | null): string { export function applyStopStateToInboundText(text: string, state: ReplyEndState | null): string {
@@ -32,5 +31,5 @@ export function applyStopStateToInboundText(text: string, state: ReplyEndState |
return text return text
} }
return `${text}\n\n[System: The user previously pressed reply-end-controls Stop for this conversation. Treat the previous thread as closed. Unless the user's new message contains a clear new instruction or explicit request for more work, you must NOT proactively continue, must NOT add extra checks, must NOT propose next steps, must NOT extend the task, and should answer briefly and close cleanly.]`.trim() return `${text}\n\n${STOP_POLICY_TEXT}`.trim()
} }