The Open Framework for Building Agents
fix(eve): preserve Telegram approval reply text (#3326)
e0-gh-vercel-connect[bot]7ba0c7770cea
diff --git a/.changeset/restore-telegram-approval-replies.md b/.changeset/restore-telegram-approval-replies.mdnew file mode 100644index 000000000..d4ed8157f--- /dev/null+++ b/.changeset/restore-telegram-approval-replies.md@@ -0,0 +1,5 @@+---+"eve": patch+---++Preserve the text of replies to Telegram approval prompts so typed approval responses resume the pending tool.diff --git a/e2e/fixtures/agent-tools-hitl-openai/evals/hitl/approve-resume.eval.ts b/e2e/fixtures/agent-tools-hitl-openai/evals/hitl/approve-resume.eval.tsindex 725129118..f0ec92120 100644--- a/e2e/fixtures/agent-tools-hitl-openai/evals/hitl/approve-resume.eval.ts+++ b/e2e/fixtures/agent-tools-hitl-openai/evals/hitl/approve-resume.eval.ts@@ -6,30 +6,31 @@ const GUARDED_ECHO_OPENAI_TOKEN = "guarded-echo-openai-ok-R2D7";* Regression coverage for https://github.com/vercel/eve/issues/236.** An `always()`-gated executable tool on the OpenAI Responses provider:- * approve-resume must execute the tool and the transcript must replay on a- * follow-up turn. For local function tools the `tool-approval-response` part- * is not a provider-level closure. OpenAI rejects any replay containing a- * `function_call` without a matching `function_call_output` with- * `No tool output found for function call call_<id>`.+ * a text approval must execute the tool and the transcript must replay on a+ * follow-up turn. This mirrors channels such as Telegram that fall back to the+ * text of a direct reply when it does not target a freeform prompt. For local+ * function tools the `tool-approval-response` part is not a provider-level+ * closure. OpenAI rejects any replay containing a `function_call` without a+ * matching `function_call_output` with `No tool output found for function+ * call call_<id>`.*/export default defineEval({tags: ["real-model"],- description: "HITL regression (#236): approve-resume executes and replays on OpenAI Responses.",+ description: "HITL regression (#236): text approval executes and replays on OpenAI Responses.",async test(t) {const parked = await t.send('Call the guarded-echo tool with note "openai-approve".');parked.calledTool("guarded-echo", { status: "pending", count: 1 });- const request = t.requireInputRequest({+ parked.notEvent("compaction.completed");+ t.requireInputRequest({display: "confirmation",toolName: "guarded-echo",});- const approved = await t.respond([- {- requestId: request.requestId,- optionId: "approve",- },- ]);+ // No compaction and no structured `respond()`: this is the payload shape+ // produced when a Telegram reply falls back to an ordinary text message.+ const approved = await t.send("approve");approved.expectOk();+ approved.notEvent("compaction.completed");approved.event("action.result", {data: {result: {@@ -44,6 +45,7 @@ export default defineEval({const followup = await t.send("Reply with exactly OPENAI-REPLAY-OK.");followup.expectOk();+ followup.notEvent("compaction.completed");followup.messageIncludes(/OPENAI-REPLAY-OK/i);t.succeeded();diff --git a/packages/eve/src/public/channels/telegram/telegramChannel.test.ts b/packages/eve/src/public/channels/telegram/telegramChannel.test.tsindex 06606f872..dcdd6ebdf 100644--- a/packages/eve/src/public/channels/telegram/telegramChannel.test.ts+++ b/packages/eve/src/public/channels/telegram/telegramChannel.test.ts@@ -330,7 +330,7 @@ describe("telegramChannel() inbound route", () => {});});- it("marks replies to bot messages as possible freeform HITL answers", async () => {+ it("keeps direct approval replies as fallback text for option prompts", async () => {const channel = telegramChannel({api: { fetch: fakeTelegramFetch() },credentials: { botToken: "bot-token", webhookSecretToken: SECRET },@@ -346,13 +346,14 @@ describe("telegramChannel() inbound route", () => {from: { id: 99, is_bot: true, username: "testbot" },chat: { id: 42, type: "private" },},- text: "approved",+ text: "approve",},});const [, input] = send.mock.calls[0]!;expect(input).toMatchObject({- inputResponses: [{ requestId: "telegram_reply:55", text: "approved" }],+ inputResponses: [{ requestId: "telegram_reply:55", text: "approve" }],+ message: expect.stringContaining("approve"),});});diff --git a/packages/eve/src/public/channels/telegram/telegramChannel.ts b/packages/eve/src/public/channels/telegram/telegramChannel.tsindex dafffc838..c99c63a35 100644--- a/packages/eve/src/public/channels/telegram/telegramChannel.ts+++ b/packages/eve/src/public/channels/telegram/telegramChannel.ts@@ -1,6 +1,11 @@import type { TelegramInstrumentationMetadata } from "#public/channels/telegram/index.js";import { defaultDeliverResult, type ChannelAdapterContext } from "#channel/adapter.js";-import type { ChannelFrom, ChannelResolveSession } from "#channel/channel-operations.js";+import {+ INTERNAL_CHANNEL_DELIVER,+ type ChannelFrom,+ type ChannelResolveSession,+ type InternalChannelSource,+} from "#channel/channel-operations.js";import type { SessionHandle } from "#channel/session.js";import type { DeliverPayload, SessionAuthContext, TurnPolicy } from "#channel/types.js";import type { SessionContext } from "#public/definitions/callback-context.js";@@ -578,7 +583,6 @@ async function dispatchMessage(input: {username: input.message.from?.username,});const channelContext = result.context ?? [];-const replyText = input.message.text || input.message.caption;const replyInputResponses =input.message.replyToMessage?.from?.isBot === true && replyText.trim().length > 0@@ -591,20 +595,17 @@ async function dispatchMessage(input: {: undefined;try {- const source = input.from(telegramContinuationTokenFromState(state));- if (replyInputResponses === undefined) {- await source.send(turnMessage, {- auth: result.auth,- context: [contextBlock, ...channelContext],- state,- title: result.title,- });- } else {- await source.respond(replyInputResponses, {- auth: result.auth,+ const source = input.from(+ telegramContinuationTokenFromState(state),+ ) as InternalChannelSource<TelegramChannelState>;+ await source[INTERNAL_CHANNEL_DELIVER](+ {context: [contextBlock, ...channelContext],- });- }+ inputResponses: replyInputResponses,+ message: turnMessage,+ },+ { auth: result.auth, state, title: result.title },+ );} catch (error) {log.error("message delivery failed", { error });}