





















@@ -42,7 +42,6 @@ import {
4242isTransientHttpError,
4343} from "../../agents/pi-embedded-helpers.js";
4444import { sanitizeUserFacingText } from "../../agents/pi-embedded-helpers/sanitize-user-facing-text.js";
45-import { isLikelyExecutionAckPrompt } from "../../agents/pi-embedded-runner/run/incomplete-turn.js";
4645import { runEmbeddedPiAgent } from "../../agents/pi-embedded.js";
4746import { buildAgentRuntimeOutcomePlan } from "../../agents/runtime-plan/build.js";
4847import {
@@ -112,10 +111,6 @@ import type { TypingSignaler } from "./typing-mode.js";
112111// selection keeps conflicting with fallback model choices.
113112// See: https://github.com/openclaw/openclaw/issues/58348
114113export const MAX_LIVE_SWITCH_RETRIES = 2;
115-const GPT_CHAT_BREVITY_ACK_MAX_CHARS = 420;
116-const GPT_CHAT_BREVITY_ACK_MAX_SENTENCES = 3;
117-const GPT_CHAT_BREVITY_SOFT_MAX_CHARS = 900;
118-const GPT_CHAT_BREVITY_SOFT_MAX_SENTENCES = 6;
119114120115function readApprovalScopeValue(value: unknown): "turn" | "session" | undefined {
121116return value === "turn" || value === "session" ? value : undefined;
@@ -857,137 +852,6 @@ export function buildContextOverflowRecoveryText(params: {
857852);
858853}
859854860-function shouldApplyOpenAIGptChatGuard(params: { provider?: string; model?: string }): boolean {
861-if (params.provider !== "openai" && params.provider !== "openai-codex") {
862-return false;
863-}
864-return /^gpt-5(?:[.-]|$)/i.test(params.model ?? "");
865-}
866-867-function countChatReplySentences(text: string): number {
868-return text
869-.trim()
870-.split(/(?<=[.!?])\s+/u)
871-.map((part) => part.trim())
872-.filter(Boolean).length;
873-}
874-875-function scoreChattyFinalReplyText(text: string): number {
876-const trimmed = text.trim();
877-if (!trimmed) {
878-return 0;
879-}
880-let score = 0;
881-const sentenceCount = countChatReplySentences(trimmed);
882-if (trimmed.length > 900) {
883-score += 1;
884-}
885-if (trimmed.length > 1_500) {
886-score += 1;
887-}
888-if (sentenceCount > 6) {
889-score += 1;
890-}
891-if (sentenceCount > 10) {
892-score += 1;
893-}
894-if (trimmed.split(/\n{2,}/u).filter(Boolean).length >= 3) {
895-score += 1;
896-}
897-if (
898-/\b(?:in summary|to summarize|here(?:'s| is) what|what changed|what I verified)\b/i.test(
899-trimmed,
900-)
901-) {
902-score += 1;
903-}
904-return score;
905-}
906-907-function shortenChattyFinalReplyText(
908-text: string,
909-params: { maxChars: number; maxSentences: number },
910-): string {
911-const trimmed = text.trim();
912-if (!trimmed) {
913-return trimmed;
914-}
915-const sentences = trimmed
916-.split(/(?<=[.!?])\s+/u)
917-.map((part) => part.trim())
918-.filter(Boolean);
919-let shortened = sentences.slice(0, params.maxSentences).join(" ");
920-if (!shortened) {
921-shortened = trimmed.slice(0, params.maxChars).trimEnd();
922-}
923-if (shortened.length > params.maxChars) {
924-shortened = shortened.slice(0, params.maxChars).trimEnd();
925-}
926-if (shortened.length >= trimmed.length) {
927-return trimmed;
928-}
929-return shortened.replace(/[.,;:!?-]*$/u, "").trimEnd() + "...";
930-}
931-932-function applyOpenAIGptChatReplyGuard(params: {
933-provider?: string;
934-model?: string;
935-commandBody: string;
936-isHeartbeat: boolean;
937-payloads?: ReplyPayload[];
938-}): void {
939-if (
940-params.isHeartbeat ||
941-!shouldApplyOpenAIGptChatGuard({
942-provider: params.provider,
943-model: params.model,
944-}) ||
945-!params.payloads?.length
946-) {
947-return;
948-}
949-950-const trimmedCommand = params.commandBody.trim();
951-const isAckTurn = isLikelyExecutionAckPrompt(trimmedCommand);
952-const allowSoftCap =
953-!isAckTurn &&
954-trimmedCommand.length > 0 &&
955-trimmedCommand.length <= 120 &&
956-!/\b(?:detail|detailed|depth|deep dive|explain|compare|walk me through|why|how)\b/i.test(
957-trimmedCommand,
958-);
959-960-for (const payload of params.payloads) {
961-const text = normalizeOptionalString(payload.text);
962-if (
963-!text ||
964-payload.isError ||
965-payload.isReasoning ||
966-payload.mediaUrl ||
967-(payload.mediaUrls?.length ?? 0) > 0 ||
968-payload.interactive ||
969-text.includes("```")
970-) {
971-continue;
972-}
973-974-if (isAckTurn) {
975-payload.text = shortenChattyFinalReplyText(text, {
976-maxChars: GPT_CHAT_BREVITY_ACK_MAX_CHARS,
977-maxSentences: GPT_CHAT_BREVITY_ACK_MAX_SENTENCES,
978-});
979-continue;
980-}
981-982-if (allowSoftCap && scoreChattyFinalReplyText(text) >= 4) {
983-payload.text = shortenChattyFinalReplyText(text, {
984-maxChars: GPT_CHAT_BREVITY_SOFT_MAX_CHARS,
985-maxSentences: GPT_CHAT_BREVITY_SOFT_MAX_SENTENCES,
986-});
987-}
988-}
989-}
990-991855function buildRestartLifecycleReplyText(): string {
992856return "⚠️ Gateway is restarting. Please wait a few seconds and try again.";
993857}
@@ -2521,14 +2385,6 @@ export async function runAgentTurnWithFallback(params: {
25212385];
25222386}
25232387}
2524-2525-applyOpenAIGptChatReplyGuard({
2526-provider: fallbackProvider,
2527-model: fallbackModel,
2528-commandBody: params.commandBody,
2529-isHeartbeat: params.isHeartbeat,
2530-payloads: runResult.payloads,
2531-});
25322388}
2533238925342390return {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。