The Open Framework for Building Agents
fix(eve): recover failed attachment downloads (#2090)
vercel-gh-bot-4[bot]62546ab5a8e3
diff --git a/.changeset/attachment-retrieval-recovery.md b/.changeset/attachment-retrieval-recovery.mdnew file mode 100644index 000000000..fefce44c0--- /dev/null+++ b/.changeset/attachment-retrieval-recovery.md@@ -0,0 +1,5 @@+---+"eve": patch+---++Continue message turns when any channel cannot retrieve an attachment, and expose a safe retrieval error to the model. Authenticate Microsoft Teams Bot Connector attachment downloads with the configured bot credentials.diff --git a/docs/channels/custom.mdx b/docs/channels/custom.mdxindex b66e8fe3a..28f4655a2 100644--- a/docs/channels/custom.mdx+++ b/docs/channels/custom.mdx@@ -405,6 +405,8 @@ defineChannel({});```+If `fetchFile` throws, eve replaces that attachment with a model-visible error note and continues the turn. Built-in channels include safe details such as the upstream HTTP status. Custom channel errors use a generic note, while eve keeps the original error in operator logs.+The `URL` object survives the queue boundary as a string and is reconstituted inside the workflow step. The staging pipeline calls `fetchFile` with the URL serialized as a string (the URL's `href`), which is why the example matches on `url.startsWith(...)`. Return bytes to stage the file to the sandbox, or `null` to let the URL pass through to the model provider.The framework handles staging bytes to the sandbox, enforcing upload policy, hydrating files for the model call, and reconstituting `URL` objects after queue serialization. See [Inbound attachments](../sandbox#inbound-attachments) for the shared storage, size, and provider-input behavior.diff --git a/docs/channels/teams.mdx b/docs/channels/teams.mdxindex 9ec8d7f54..a4763d79a 100644--- a/docs/channels/teams.mdx+++ b/docs/channels/teams.mdx@@ -70,10 +70,15 @@ Inbound files are off by default. Opt in to allow personal-scope downloads and p```tsexport default teamsChannel({- files: { enabled: true, allowedHosts: ["contoso.sharepoint.com"] },+ files: {+ enabled: true,+ allowedHosts: ["smba.trafficmanager.net", "contoso.sharepoint.com"],+ },});```+eve authenticates downloads from Microsoft Bot Connector hosts with your bot credentials. Downloads from other allowlisted hosts remain unauthenticated.+## What to read next- [Channels overview](./overview): the channel contract and every built-in channeldiff --git a/packages/eve/src/harness/attachment-staging.integration.test.ts b/packages/eve/src/harness/attachment-staging.integration.test.tsindex c1baafbd0..f6272658c 100644--- a/packages/eve/src/harness/attachment-staging.integration.test.ts+++ b/packages/eve/src/harness/attachment-staging.integration.test.ts@@ -298,8 +298,8 @@ describe("stageAttachmentsToSandbox (integration)", () => {expect(sandbox.writes).toHaveLength(0);});- it("wraps uncategorized fetchFile throws as resolver-threw", async () => {- const upstream = new Error("boom");+ it("degrades plain resolver errors to a channel-neutral safe note", async () => {+ const upstream = new Error("boom https://secret.example/file?token=private");const adapter: ChannelAdapter<any> = {async fetchFile() {throw upstream;@@ -318,18 +318,25 @@ describe("stageAttachmentsToSandbox (integration)", () => {},];- await expect(- runtime.runAsSession({ channel: adapter, sandbox }, async () =>- stageAttachmentsToSandbox(content),- ),- ).rejects.toMatchObject({ cause: upstream, kind: "resolver-threw" });+ const staged = (await runtime.runAsSession({ channel: adapter, sandbox }, async () =>+ stageAttachmentsToSandbox(content),+ )) as Exclude<UserContent, string>;++ expect(staged).toEqual([+ {+ text: 'Attachment a.bin could not be retrieved: Attachment retrieval failed in the "custom-channel" channel.',+ type: "text",+ },+ ]);+ expect(staged[0]).not.toHaveProperty("text", expect.stringContaining("secret.example"));+ expect(sandbox.writes).toHaveLength(0);});- it("propagates EveAttachmentError from fetchFile unchanged", async () => {+ it("exposes a channel-authored safe resolver error to the model", async () => {const resolverError = new EveAttachmentError({adapterKind: "custom-channel",kind: "resolver-threw",- message: "test resolver error",+ message: "Slack file fetch returned HTTP 403.",});const adapter: ChannelAdapter<any> = {async fetchFile() {@@ -349,11 +356,61 @@ describe("stageAttachmentsToSandbox (integration)", () => {},];- await expect(- runtime.runAsSession({ channel: adapter, sandbox }, async () =>- stageAttachmentsToSandbox(content),- ),- ).rejects.toBe(resolverError);+ const staged = (await runtime.runAsSession({ channel: adapter, sandbox }, async () =>+ stageAttachmentsToSandbox(content),+ )) as Exclude<UserContent, string>;++ expect(staged).toEqual([+ {+ text: "Attachment a.bin could not be retrieved: Slack file fetch returned HTTP 403.",+ type: "text",+ },+ ]);+ expect(sandbox.writes).toHaveLength(0);+ });++ it("stages sibling attachments when one resolver call fails", async () => {+ const adapter: ChannelAdapter<any> = {+ async fetchFile(url) {+ if (url.endsWith("missing.bin")) {+ throw new EveAttachmentError({+ adapterKind: "custom-channel",+ kind: "resolver-threw",+ message: "Attachment service returned HTTP 503.",+ });+ }+ return { bytes: Buffer.from("available") };+ },+ kind: "custom-channel",+ state: {},+ };+ const sandbox = mockSandbox({ id: "sbx_partial_failure" });+ const runtime = await createTestRuntime();+ const content: UserContent = [+ {+ data: new URL("https://example.com/missing.bin"),+ filename: "missing.bin",+ mediaType: "application/octet-stream",+ type: "file",+ },+ {+ data: new URL("https://example.com/available.bin"),+ filename: "available.bin",+ mediaType: "application/octet-stream",+ type: "file",+ },+ ];++ const staged = (await runtime.runAsSession({ channel: adapter, sandbox }, async () =>+ stageAttachmentsToSandbox(content),+ )) as Exclude<UserContent, string>;++ expect(staged[0]).toEqual({+ text: "Attachment missing.bin could not be retrieved: Attachment service returned HTTP 503.",+ type: "text",+ });+ expect((staged[1] as FilePart).filename).toMatch(/\/available\.bin$/);+ expect(sandbox.writes).toHaveLength(1);});it("works alongside non-file parts in the same user message", async () => {diff --git a/packages/eve/src/harness/attachment-staging.ts b/packages/eve/src/harness/attachment-staging.tsindex 20c378d7b..b41db691f 100644--- a/packages/eve/src/harness/attachment-staging.ts+++ b/packages/eve/src/harness/attachment-staging.ts@@ -20,7 +20,6 @@ import {type SandboxRef,} from "#internal/attachments/sandbox-refs.js";import type { SandboxSession } from "#public/definitions/sandbox.js";-import { toErrorMessage } from "#shared/errors.js";/*** Sandbox directory where inbound file attachments are staged before the@@ -290,14 +289,30 @@ async function stageFilePart(part: FilePart,sandbox: SandboxSession,adapterCtx: ChannelAdapterContext,-): Promise<FilePart> {+): Promise<FilePart | TextPart> {if (isSandboxRefUrl(part.data)) {return part;}// URL objects (including reconstituted ones) → try fetchFileif (part.data instanceof URL && part.data.protocol !== "data:") {- const resolved = await tryFetchFile(part.data.href, adapterCtx);+ let resolved: FetchFileResult | null;+ try {+ resolved = await tryFetchFile(part.data.href, adapterCtx);+ } catch (error) {+ if (!(error instanceof EveAttachmentError)) throw error;+ const filename = part.filename?.trim() || "file";+ log.warn("attachment resolver failed — degrading to text part", {+ adapterKind: error.adapterKind,+ error: error.cause,+ filename,+ kind: error.kind,+ });+ return {+ text: `Attachment ${filename} could not be retrieved: ${error.message}`,+ type: "text",+ };+ }if (resolved === null) {return part;}@@ -358,7 +373,7 @@ async function tryFetchFile(adapterKind,cause,kind: "resolver-threw",- message: `fetchFile for adapter kind="${adapterKind}" threw: ${toErrorMessage(cause)}`,+ message: `Attachment retrieval failed in the "${adapterKind}" channel.`,});}}diff --git a/packages/eve/src/internal/attachments/errors.ts b/packages/eve/src/internal/attachments/errors.tsindex 324f96a8c..c32a44f1d 100644--- a/packages/eve/src/internal/attachments/errors.ts+++ b/packages/eve/src/internal/attachments/errors.ts@@ -28,6 +28,9 @@ interface EveAttachmentErrorInput {* Channels can inspect the `.kind` discriminator to decide whether to* drop the attachment and continue the turn (the default posture for* every kind today) or fail the whole delivery (future strict mode).+ * `.message` crosses into model-visible input when the attachment is+ * dropped, so it must not contain URLs, credentials, or verbatim upstream+ * error text. Preserve private diagnostics on `.cause` instead.* The original failure, when there is one, is preserved on `.cause` so* observability can surface the upstream error without losing context.*/diff --git a/packages/eve/src/public/channels/slack/attachments.test.ts b/packages/eve/src/public/channels/slack/attachments.test.tsindex b48713238..232203319 100644--- a/packages/eve/src/public/channels/slack/attachments.test.ts+++ b/packages/eve/src/public/channels/slack/attachments.test.ts@@ -233,7 +233,9 @@ describe("createSlackFetchFile", () => {const fetchFile = createSlackFetchFile({ botToken: "xoxb-test-token" });- await expect(fetchFile("https://files.slack.com/locked.csv")).rejects.toThrow("HTTP 403");+ const result = fetchFile("https://files.slack.com/locked.csv?sig=PRIVATE");+ await expect(result).rejects.toThrow("HTTP 403");+ await expect(result).rejects.not.toThrow("PRIVATE");});it("rejects HTML returned for a private Slack file", async () => {@@ -246,9 +248,9 @@ describe("createSlackFetchFile", () => {const fetchFile = createSlackFetchFile({ botToken: "xoxb-test-token" });- await expect(fetchFile("https://files.slack.com/locked.png")).rejects.toThrow(- /files:read.*reinstall/is,- );+ const result = fetchFile("https://files.slack.com/locked.png?sig=PRIVATE");+ await expect(result).rejects.toThrow(/files:read.*reinstall/is);+ await expect(result).rejects.not.toThrow("PRIVATE");});});diff --git a/packages/eve/src/public/channels/slack/attachments.ts b/packages/eve/src/public/channels/slack/attachments.tsindex 8ebb20f94..9c89c3e68 100644--- a/packages/eve/src/public/channels/slack/attachments.ts+++ b/packages/eve/src/public/channels/slack/attachments.ts@@ -1,6 +1,7 @@import type { FilePart, TextPart, UserContent } from "ai";import type { FetchFileContext, FetchFileResult } from "#channel/adapter.js";+import { EveAttachmentError } from "#internal/attachments/errors.js";import { createLogger } from "#internal/logging.js";import {resolveSlackBotToken,@@ -180,15 +181,21 @@ export function createSlackFetchFile(input: {headers: { authorization: `Bearer ${token}` },});if (!response.ok) {- throw new Error(`Slack file fetch returned HTTP ${response.status} for ${url}.`);+ throw new EveAttachmentError({+ adapterKind: "slack",+ kind: "resolver-threw",+ message: `Slack file fetch returned HTTP ${response.status}.`,+ });}const mediaType = response.headers.get("content-type") ?? undefined;const normalizedMediaType = mediaType?.split(";", 1)[0]?.trim().toLowerCase();if (normalizedMediaType === "text/html") {- throw new Error(- `Slack file fetch returned an HTML sign-in page instead of file bytes for ${url}. ` +- "The bot token may be missing the files:read scope. Add the scope, reinstall the Slack app, and retry.",- );+ throw new EveAttachmentError({+ adapterKind: "slack",+ kind: "resolver-threw",+ message:+ "Slack returned an HTML sign-in page instead of file bytes. The bot token may be missing the files:read scope. Add the scope, reinstall the Slack app, and retry.",+ });}return {bytes: Buffer.from(await response.arrayBuffer()),diff --git a/packages/eve/src/public/channels/teams/attachments.test.ts b/packages/eve/src/public/channels/teams/attachments.test.tsnew file mode 100644index 000000000..1bf4dbbad--- /dev/null+++ b/packages/eve/src/public/channels/teams/attachments.test.ts@@ -0,0 +1,182 @@+import { afterEach, describe, expect, it, vi } from "vitest";++import { createTeamsFetchFile, normalizeTeamsFilesPolicy } from "./attachments.js";++describe("createTeamsFetchFile", () => {+ afterEach(() => {+ vi.unstubAllGlobals();+ });++ it.each([+ "smba.trafficmanager.net",+ "smba.infra.gcc.teams.microsoft.com",+ "smba.infra.gov.teams.microsoft.us",+ "smba.infra.dod.teams.microsoft.us",+ ])("authenticates Bot Framework attachment downloads from %s", async (host) => {+ const apiFetch = vi.fn(async (_url: string | URL | Request, init?: RequestInit) => {+ expect(new Headers(init?.headers).get("authorization")).toBe("Bearer connector-token");+ return new Response(Buffer.from("image"), {+ headers: { "content-type": "image/png" },+ });+ });+ vi.stubGlobal("fetch", apiFetch);++ const fetchFile = createTeamsFetchFile(+ normalizeTeamsFilesPolicy({+ allowedHosts: [host],+ enabled: true,+ }),+ {+ credentials: { tokenProvider: () => "connector-token" },+ fetch: apiFetch,+ },+ );++ await expect(+ fetchFile(`https://${host}/amer/v3/attachments/ATTACHMENT/views/original`),+ ).resolves.toMatchObject({ mediaType: "image/png" });+ expect(apiFetch).toHaveBeenCalledTimes(1);+ });++ it.each(["https://smba.trafficmanager.net.evil.example/attachments/image"])(+ "does not send the Connector token to lookalike URLs: %s",+ async (url) => {+ const host = new URL(url).hostname;+ const apiFetch = vi.fn(async (_url: string | URL | Request, init?: RequestInit) => {+ expect(new Headers(init?.headers).has("authorization")).toBe(false);+ return new Response(Buffer.from("file"));+ });+ const tokenProvider = vi.fn(() => "connector-token");+ const fetchFile = createTeamsFetchFile(+ normalizeTeamsFilesPolicy({ allowedHosts: [host], enabled: true }),+ { credentials: { tokenProvider }, fetch: apiFetch },+ );++ await expect(fetchFile(url)).resolves.toBeTruthy();+ expect(tokenProvider).not.toHaveBeenCalled();+ },+ );++ it("rejects insecure URLs before fetching", async () => {+ const apiFetch = vi.fn();+ const fetchFile = createTeamsFetchFile(+ normalizeTeamsFilesPolicy({ allowedHosts: ["smba.trafficmanager.net"], enabled: true }),+ { credentials: { tokenProvider: () => "connector-token" }, fetch: apiFetch },+ );++ await expect(fetchFile("http://smba.trafficmanager.net/attachments/image")).resolves.toBeNull();+ expect(apiFetch).not.toHaveBeenCalled();+ });++ it("rejects alternate ports unless the allowlist names the port", async () => {+ const apiFetch = vi.fn();+ const tokenProvider = vi.fn(() => "connector-token");+ const fetchFile = createTeamsFetchFile(+ normalizeTeamsFilesPolicy({ allowedHosts: ["smba.trafficmanager.net"], enabled: true }),+ { credentials: { tokenProvider }, fetch: apiFetch },+ );++ await expect(+ fetchFile("https://smba.trafficmanager.net:8443/attachments/image"),+ ).resolves.toBeNull();+ expect(apiFetch).not.toHaveBeenCalled();+ expect(tokenProvider).not.toHaveBeenCalled();+ });++ it("never authenticates an explicitly allowlisted alternate port", async () => {+ const apiFetch = vi.fn(async (_url: string | URL | Request, init?: RequestInit) => {+ expect(new Headers(init?.headers).has("authorization")).toBe(false);+ return new Response(Buffer.from("file"));+ });+ const tokenProvider = vi.fn(() => "connector-token");+ const fetchFile = createTeamsFetchFile(+ normalizeTeamsFilesPolicy({+ allowedHosts: ["smba.trafficmanager.net:8443"],+ enabled: true,+ }),+ { credentials: { tokenProvider }, fetch: apiFetch },+ );++ await expect(+ fetchFile("https://smba.trafficmanager.net:8443/attachments/image"),+ ).resolves.toBeTruthy();+ expect(tokenProvider).not.toHaveBeenCalled();+ });++ it("never sends the Connector token to arbitrary allowlisted hosts", async () => {+ const apiFetch = vi.fn(async (_url: string | URL | Request, init?: RequestInit) => {+ expect(new Headers(init?.headers).has("authorization")).toBe(false);+ return new Response(Buffer.from("public file"));+ });+ const tokenProvider = vi.fn(() => "connector-token");++ const fetchFile = createTeamsFetchFile(+ normalizeTeamsFilesPolicy({ allowedHosts: ["files.example.com"], enabled: true }),+ { credentials: { tokenProvider }, fetch: apiFetch },+ );++ await expect(fetchFile("https://files.example.com/report.pdf")).resolves.toBeTruthy();+ expect(tokenProvider).not.toHaveBeenCalled();+ });++ it("reports the status and host without leaking signed URL query parameters", async () => {+ const apiFetch = vi.fn(async () => new Response(null, { status: 401 }));+ const fetchFile = createTeamsFetchFile(+ normalizeTeamsFilesPolicy({+ allowedHosts: ["smba.trafficmanager.net"],+ enabled: true,+ }),+ {+ credentials: { tokenProvider: () => "connector-token" },+ fetch: apiFetch,+ },+ );++ const result = fetchFile("https://smba.trafficmanager.net/attachments/image?sig=SECRET");+ await expect(result).rejects.toThrow("HTTP 401 for host smba.trafficmanager.net");+ await expect(result).rejects.not.toThrow("SECRET");+ });++ it.each([+ "https://files.example.com/redirected",+ "http://smba.trafficmanager.net/attachments/image",+ "https://smba.trafficmanager.net:8443/attachments/image",+ "https://smba.trafficmanager.net.evil.example/attachments/image",+ ])("rejects disallowed redirects before requesting %s", async (location) => {+ const apiFetch = vi.fn(async () => Response.redirect(location, 302));+ const fetchFile = createTeamsFetchFile(+ normalizeTeamsFilesPolicy({ allowedHosts: ["smba.trafficmanager.net"], enabled: true }),+ { credentials: { tokenProvider: () => "connector-token" }, fetch: apiFetch },+ );++ await expect(fetchFile("https://smba.trafficmanager.net/attachments/image")).rejects.toThrow(+ "not allowed",+ );+ expect(apiFetch).toHaveBeenCalledTimes(1);+ });++ it("revalidates allowed redirects without forwarding the Connector token", async () => {+ const apiFetch = vi+ .fn<typeof fetch>()+ .mockImplementationOnce(async (_url, init) => {+ expect(new Headers(init?.headers).get("authorization")).toBe("Bearer connector-token");+ return Response.redirect("https://files.example.com/image", 302);+ })+ .mockImplementationOnce(async (_url, init) => {+ expect(new Headers(init?.headers).has("authorization")).toBe(false);+ return new Response(Buffer.from("image"), { headers: { "content-type": "image/png" } });+ });+ const fetchFile = createTeamsFetchFile(+ normalizeTeamsFilesPolicy({+ allowedHosts: ["smba.trafficmanager.net", "files.example.com"],+ enabled: true,+ }),+ { credentials: { tokenProvider: () => "connector-token" }, fetch: apiFetch },+ );++ await expect(+ fetchFile("https://smba.trafficmanager.net/attachments/image"),+ ).resolves.toMatchObject({ mediaType: "image/png" });+ expect(apiFetch).toHaveBeenCalledTimes(2);+ });+});diff --git a/packages/eve/src/public/channels/teams/attachments.ts b/packages/eve/src/public/channels/teams/attachments.tsindex 24ea64c09..271cd2ee3 100644--- a/packages/eve/src/public/channels/teams/attachments.ts+++ b/packages/eve/src/public/channels/teams/attachments.ts@@ -1,8 +1,13 @@import type { FilePart, TextPart, UserContent } from "ai";import type { FetchFileResult } from "#channel/adapter.js";+import { EveAttachmentError } from "#internal/attachments/errors.js";import { createLogger } from "#internal/logging.js";-import type { TeamsAttachment } from "#public/channels/teams/api.js";+import {+ resolveTeamsAccessToken,+ type TeamsApiOptions,+ type TeamsAttachment,+} from "#public/channels/teams/api.js";import {evaluateFilePart,formatUploadPolicyViolation,@@ -15,6 +20,15 @@ import { isObject } from "#shared/guards.js";const log = createLogger("teams.attachments");+const BOT_CONNECTOR_HOSTS = new Set([+ "smba.trafficmanager.net",+ "smba.infra.gcc.teams.microsoft.com",+ "smba.infra.gov.teams.microsoft.us",+ "smba.infra.dod.teams.microsoft.us",+]);+const MAX_FILE_REDIRECTS = 5;+const REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);+/** File handling options for the native Teams channel. */export interface TeamsFilesConfig {/**@@ -86,12 +100,15 @@ export function buildTeamsTurnMessage(*/export function createTeamsFetchFile(policy: TeamsFilesPolicy,+ api: TeamsApiOptions = {},): (url: string) => Promise<FetchFileResult | null> {return async (url) => {if (!policy.enabled || !isAllowedUrl(url, policy.allowedHosts)) return null;- const response = await fetch(url);+ const { response, finalUrl } = await fetchTeamsFile(url, policy.allowedHosts, api);if (!response.ok) {- throw new Error(`Teams file fetch returned HTTP ${response.status} for ${url}.`);+ throw attachmentError(+ `Teams file fetch returned HTTP ${response.status} for host ${finalUrl.hostname}.`,+ );}return {bytes: Buffer.from(await response.arrayBuffer()),@@ -100,6 +117,55 @@ export function createTeamsFetchFile(};}+async function fetchTeamsFile(+ url: string,+ allowedHosts: readonly string[] | "*",+ api: TeamsApiOptions,+): Promise<{ readonly finalUrl: URL; readonly response: Response }> {+ const apiFetch = api.fetch ?? fetch;+ let currentUrl = new URL(url);+ let connectorToken: string | undefined;++ for (let redirectCount = 0; redirectCount <= MAX_FILE_REDIRECTS; redirectCount += 1) {+ const isBotConnectorUrl =+ currentUrl.port === "" && BOT_CONNECTOR_HOSTS.has(currentUrl.hostname);+ const headers = new Headers();+ if (isBotConnectorUrl) {+ connectorToken ??= await resolveTeamsAccessToken(api);+ headers.set("authorization", `Bearer ${connectorToken}`);+ }+ const response = await apiFetch(currentUrl, {+ headers,+ redirect: "manual",+ });+ if (!REDIRECT_STATUSES.has(response.status)) {+ return { finalUrl: currentUrl, response };+ }+ if (redirectCount === MAX_FILE_REDIRECTS) {+ throw attachmentError(`Teams file fetch exceeded ${MAX_FILE_REDIRECTS} redirects.`);+ }+ const location = response.headers.get("location");+ if (location === null) {+ throw attachmentError(+ `Teams file fetch redirect from host ${currentUrl.hostname} had no location.`,+ );+ }+ const nextUrl = new URL(location, currentUrl);+ if (!isAllowedUrl(nextUrl.href, allowedHosts)) {+ throw attachmentError(+ `Teams file fetch redirect to host ${nextUrl.hostname} is not allowed.`,+ );+ }+ currentUrl = nextUrl;+ }++ throw attachmentError(`Teams file fetch exceeded ${MAX_FILE_REDIRECTS} redirects.`);+}++function attachmentError(message: string): EveAttachmentError {+ return new EveAttachmentError({ adapterKind: "teams", kind: "resolver-threw", message });+}+function toTeamsFilePart(attachment: TeamsAttachment,index: number,@@ -145,12 +211,15 @@ function inferMediaType(attachment: TeamsAttachment): string {}function isAllowedUrl(url: string, allowedHosts: readonly string[] | "*"): boolean {- if (allowedHosts === "*") return true;let parsed: URL;try {parsed = new URL(url);} catch {return false;}- return allowedHosts.some((host) => parsed.host === host || parsed.hostname === host);+ if (parsed.protocol !== "https:") return false;+ if (allowedHosts === "*") return true;+ return allowedHosts.some((host) =>+ host.includes(":") ? parsed.host === host : parsed.port === "" && parsed.hostname === host,+ );}diff --git a/packages/eve/src/public/channels/teams/teamsChannel.ts b/packages/eve/src/public/channels/teams/teamsChannel.tsindex e58d6be03..64b987113 100644--- a/packages/eve/src/public/channels/teams/teamsChannel.ts+++ b/packages/eve/src/public/channels/teams/teamsChannel.ts@@ -302,7 +302,10 @@ export function teamsChannel(config: TeamsChannelConfig = {}): TeamsChannel {kindHint: "teams",turnPolicy: config.turnPolicy,state: initialTeamsState(),- fetchFile: createTeamsFetchFile(filesPolicy),+ fetchFile: createTeamsFetchFile(filesPolicy, {+ ...config.api,+ credentials: config.credentials,+ }),metadata: (state) => ({audience: teamsAudience(state.conversationType),channelId: state.channelId,diff --git a/packages/eve/src/public/channels/telegram/attachments.test.ts b/packages/eve/src/public/channels/telegram/attachments.test.tsindex fa96b3f8f..d74bf524e 100644--- a/packages/eve/src/public/channels/telegram/attachments.test.ts+++ b/packages/eve/src/public/channels/telegram/attachments.test.ts@@ -86,4 +86,28 @@ describe("createTelegramFetchFile", () => {await expect(fetchFile("https://example.com/file.png")).resolves.toBeNull();});++ it("reports download status without exposing the Telegram file reference", async () => {+ const fetchMock = vi+ .fn()+ .mockResolvedValueOnce(+ new Response(JSON.stringify({ ok: true, result: { file_path: "private/path.pdf" } }), {+ headers: { "content-type": "application/json" },+ }),+ )+ .mockResolvedValueOnce(new Response("forbidden", { status: 403 }));+ const fetchFile = createTelegramFetchFile({+ api: { apiBaseUrl: "https://telegram.example", fetch: fetchMock },+ credentials: { botToken: "123456:PRIVATE" },+ policy: { allowedMediaTypes: "*", maxBytes: 1024 },+ });+ const reference = String(+ createTelegramFileUrl({ fileId: "PRIVATE_FILE_ID", filename: "report.pdf" }),+ );++ const result = fetchFile(reference);+ await expect(result).rejects.toThrow("HTTP 403");+ await expect(result).rejects.not.toThrow("PRIVATE_FILE_ID");+ await expect(result).rejects.not.toThrow("123456:PRIVATE");+ });});diff --git a/packages/eve/src/public/channels/telegram/attachments.ts b/packages/eve/src/public/channels/telegram/attachments.tsindex a18e0e022..c6120b457 100644--- a/packages/eve/src/public/channels/telegram/attachments.ts+++ b/packages/eve/src/public/channels/telegram/attachments.ts@@ -1,6 +1,7 @@import type { FilePart, TextPart, UserContent } from "ai";import type { FetchFileResult } from "#channel/adapter.js";+import { EveAttachmentError } from "#internal/attachments/errors.js";import { createLogger } from "#internal/logging.js";import {downloadTelegramFile,@@ -86,7 +87,11 @@ export function createTelegramFetchFile(input: {filePath: file.filePath,});if (!response.ok) {- throw new Error(`Telegram file fetch returned HTTP ${response.status} for ${url}.`);+ throw new EveAttachmentError({+ adapterKind: "telegram",+ kind: "resolver-threw",+ message: `Telegram file fetch returned HTTP ${response.status}.`,+ });}const bytes = Buffer.from(await response.arrayBuffer());@@ -108,7 +113,11 @@ export function createTelegramFetchFile(input: {input.policy,);if (violation !== null) {- throw new Error(`Telegram file rejected — ${formatUploadPolicyViolation(violation)}`);+ throw new EveAttachmentError({+ adapterKind: "telegram",+ kind: "resolver-threw",+ message: `Telegram file rejected — ${formatUploadPolicyViolation(violation)}`,+ });}return result;};