From abde0c243f77101d13ddb7748a7ed149bc7113b1 Mon Sep 17 00:00:00 2001 From: "Alice (OpenClaw)" Date: Wed, 13 May 2026 14:21:43 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20extract=20reply-end=20config=20cons?= =?UTF-8?q?tants=20/=20=E6=8A=BD=E5=87=BA=20reply-end=20=E5=85=B1=E7=94=A8?= =?UTF-8?q?=E8=A8=AD=E5=AE=9A=E5=B8=B8=E6=95=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config.ts | 24 ++++++++++++++++++++++++ src/runtime/openclaw-telegram-poc.ts | 19 +++++++++---------- 2 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 src/config.ts diff --git a/src/config.ts b/src/config.ts new file mode 100644 index 0000000..783e038 --- /dev/null +++ b/src/config.ts @@ -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.]" diff --git a/src/runtime/openclaw-telegram-poc.ts b/src/runtime/openclaw-telegram-poc.ts index e1cb6f1..bcba16a 100644 --- a/src/runtime/openclaw-telegram-poc.ts +++ b/src/runtime/openclaw-telegram-poc.ts @@ -1,30 +1,29 @@ 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[][] { return [[ - { text: "A. 繼續", callback_data: "rec:continue" }, - { text: "B. 就這樣吧,不需要額外處理", callback_data: "rec:stop" }, + { text: REPLY_END_LABELS.continue, callback_data: REPLY_END_CALLBACKS.continue }, + { text: REPLY_END_LABELS.stop, callback_data: REPLY_END_CALLBACKS.stop }, ]] } export function buildResolvedReplyEndButtons(choice: ReplyEndChoice): TelegramInlineButton[][] { if (choice === "continue") { return [[ - { text: "✅ A. 繼續", callback_data: "rec:continue" }, - { text: "B. 就這樣吧,不需要額外處理", callback_data: "rec:stop" }, + { text: REPLY_END_RESOLVED_LABELS.continue, callback_data: REPLY_END_CALLBACKS.continue }, + { text: REPLY_END_LABELS.stop, callback_data: REPLY_END_CALLBACKS.stop }, ]] } return [[ - { text: "A. 繼續", callback_data: "rec:continue" }, - { text: "⏹ B. 就這樣吧,不需要額外處理", callback_data: "rec:stop" }, + { text: REPLY_END_LABELS.continue, callback_data: REPLY_END_CALLBACKS.continue }, + { text: REPLY_END_RESOLVED_LABELS.stop, callback_data: REPLY_END_CALLBACKS.stop }, ]] } export function buildReplyEndAcknowledgement(choice: ReplyEndChoice): string { - return choice === "continue" - ? "reply-end-controls: continue received" - : "reply-end-controls: stop received" + return buildReplyEndAckText(choice) } export function applyStopStateToInboundText(text: string, state: ReplyEndState | null): string { @@ -32,5 +31,5 @@ export function applyStopStateToInboundText(text: string, state: ReplyEndState | 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() }