chore: align patch flow with repo-side contracts / 對齊 patch 流程與 repo-side contracts

This commit is contained in:
Alice (OpenClaw)
2026-05-14 09:54:10 +08:00
parent e14f63b510
commit 9cb368bbd2
3 changed files with 15 additions and 9 deletions

View File

@@ -9,7 +9,6 @@ fi
DIST_DIR="$1" DIST_DIR="$1"
SEND_JS="${DIST_DIR}/send-sxDwUGaO.js" SEND_JS="${DIST_DIR}/send-sxDwUGaO.js"
BOT_JS="${DIST_DIR}/bot-Ce301bOE.js" BOT_JS="${DIST_DIR}/bot-Ce301bOE.js"
CONFIG_PATH="$(dirname "$0")/../config/reply-end-controls.json"
PATCH_CONTRACT_PATH="$(dirname "$0")/../generated/openclaw-telegram-patch-contract.json" PATCH_CONTRACT_PATH="$(dirname "$0")/../generated/openclaw-telegram-patch-contract.json"
mkdir -p "$(dirname "${PATCH_CONTRACT_PATH}")" mkdir -p "$(dirname "${PATCH_CONTRACT_PATH}")"
@@ -23,27 +22,25 @@ fi
cp "${SEND_JS}" "${SEND_JS}.reply-end-controls.bak" cp "${SEND_JS}" "${SEND_JS}.reply-end-controls.bak"
cp "${BOT_JS}" "${BOT_JS}.reply-end-controls.bak" cp "${BOT_JS}" "${BOT_JS}.reply-end-controls.bak"
python3 - <<'PY' "${SEND_JS}" "${BOT_JS}" "${CONFIG_PATH}" "${PATCH_CONTRACT_PATH}" python3 - <<'PY' "${SEND_JS}" "${BOT_JS}" "${PATCH_CONTRACT_PATH}"
from pathlib import Path from pathlib import Path
import json import json
import sys import sys
send_js = Path(sys.argv[1]) send_js = Path(sys.argv[1])
bot_js = Path(sys.argv[2]) bot_js = Path(sys.argv[2])
config_path = Path(sys.argv[3]) patch_contract_path = Path(sys.argv[3])
patch_contract_path = Path(sys.argv[4])
cfg = json.loads(config_path.read_text(encoding='utf-8'))
contract = json.loads(patch_contract_path.read_text(encoding='utf-8')) contract = json.loads(patch_contract_path.read_text(encoding='utf-8'))
cb_continue = cfg['callbacks']['continue'] cb_continue = contract['defaultButtons'][0][0]['callback_data']
cb_stop = cfg['callbacks']['stop'] cb_stop = contract['defaultButtons'][0][1]['callback_data']
label_continue = contract['defaultButtons'][0][0]['text'] label_continue = contract['defaultButtons'][0][0]['text']
label_stop = contract['defaultButtons'][0][1]['text'] label_stop = contract['defaultButtons'][0][1]['text']
resolved_continue = contract['resolved']['continue']['buttons'][0][0]['text'] resolved_continue = contract['resolved']['continue']['buttons'][0][0]['text']
resolved_stop = contract['resolved']['stop']['buttons'][0][1]['text'] resolved_stop = contract['resolved']['stop']['buttons'][0][1]['text']
ack_continue = contract['resolved']['continue']['acknowledgement'] ack_continue = contract['resolved']['continue']['acknowledgement']
ack_stop = contract['resolved']['stop']['acknowledgement'] ack_stop = contract['resolved']['stop']['acknowledgement']
stop_policy = cfg['stopPolicyText'] stop_policy = contract['stopPolicyText']
send_text = send_js.read_text(encoding='utf-8') send_text = send_js.read_text(encoding='utf-8')
send_old = 'const replyMarkup = buildInlineKeyboard(opts.buttons);' send_old = 'const replyMarkup = buildInlineKeyboard(opts.buttons);'

View File

@@ -1,5 +1,5 @@
import type { ReplyEndChoice, TelegramInlineButton } from "../types.js" import type { ReplyEndChoice, TelegramInlineButton } from "../types.js"
import { buildTelegramReplyEndAck, buildTelegramReplyEndButtonsForReply, buildTelegramReplyEndButtonsForResolvedChoice } from "./openclaw-telegram-bridge.js" import { applyTelegramReplyEndStopPolicy, buildTelegramReplyEndAck, buildTelegramReplyEndButtonsForReply, buildTelegramReplyEndButtonsForResolvedChoice } from "./openclaw-telegram-bridge.js"
export type OpenClawTelegramPatchContract = { export type OpenClawTelegramPatchContract = {
defaultButtons: TelegramInlineButton[][] defaultButtons: TelegramInlineButton[][]
@@ -7,6 +7,7 @@ export type OpenClawTelegramPatchContract = {
buttons: TelegramInlineButton[][] buttons: TelegramInlineButton[][]
acknowledgement: string acknowledgement: string
}> }>
stopPolicyText: string
} }
export function buildOpenClawTelegramPatchContract(): OpenClawTelegramPatchContract { export function buildOpenClawTelegramPatchContract(): OpenClawTelegramPatchContract {
@@ -22,5 +23,12 @@ export function buildOpenClawTelegramPatchContract(): OpenClawTelegramPatchContr
acknowledgement: buildTelegramReplyEndAck("stop"), acknowledgement: buildTelegramReplyEndAck("stop"),
}, },
}, },
stopPolicyText: applyTelegramReplyEndStopPolicy("__BASE__", {
lastChoice: "stop",
lastChoiceAt: "1970-01-01T00:00:00Z",
sourceMessageId: "0",
sourceCallbackId: "0",
active: true,
}).replace("__BASE__\n\n", ""),
} }
} }

View File

@@ -11,4 +11,5 @@ test("patch contract exposes default and resolved callback behavior from shared
assert.match(contract.resolved.stop.buttons[0][1].text, /^⏹/) assert.match(contract.resolved.stop.buttons[0][1].text, /^⏹/)
assert.equal(contract.resolved.continue.acknowledgement, "reply-end-controls: continue received") assert.equal(contract.resolved.continue.acknowledgement, "reply-end-controls: continue received")
assert.equal(contract.resolved.stop.acknowledgement, "reply-end-controls: stop received") assert.equal(contract.resolved.stop.acknowledgement, "reply-end-controls: stop received")
assert.match(contract.stopPolicyText, /reply-end-controls Stop/)
}) })