Skip to content

Commit 2c125ad

Browse files
committed
fix(agent-gateway): keep attachment names in unsupported-image fallback notices
When persistence of an unsupported inline image fails, include the supplied name in the omitted-image notice so it matches the successful-persist path.
1 parent f29c5a6 commit 2c125ad

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

‎packages/agent-gateway/src/lib/promptMedia.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ export async function resolvePromptMediaFiles(
224224
content.push({
225225
type: 'text',
226226
text: persisted === null
227-
? buildUnsupportedImageNotice(effectiveMime)
227+
? buildUnsupportedImageNotice(effectiveMime, name)
228228
: buildAttachedFileNotice(name, effectiveMime, bytes.length, persisted),
229229
});
230230
if (persisted !== null) {

‎packages/agent-gateway/test/prompts.test.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,43 @@ describe('server-v2 /api/v1 prompts', () => {
10561056
expect(await readFile(attachedPath)).toEqual(data);
10571057
});
10581058

1059+
it('keeps the supplied name in the notice when unsupported-image persistence fails', async () => {
1060+
const cacheDir = await mkdtemp(join(tmpdir(), 'pythinker-prompt-media-'));
1061+
try {
1062+
const store = {
1063+
save: vi.fn(async () => {
1064+
throw new Error('disk full');
1065+
}),
1066+
delete: vi.fn(async () => undefined),
1067+
get: vi.fn(),
1068+
};
1069+
const prepared = await resolvePromptMediaFiles(
1070+
[
1071+
{
1072+
type: 'image',
1073+
name: 'scan.avif',
1074+
source: {
1075+
kind: 'base64',
1076+
media_type: 'image/avif',
1077+
data: avifBytes().toString('base64'),
1078+
},
1079+
},
1080+
],
1081+
store as unknown as IFileService,
1082+
cacheDir,
1083+
);
1084+
expect(prepared.content).toHaveLength(1);
1085+
const notice = prepared.content[0];
1086+
if (notice?.type !== 'text') throw new Error('expected a text notice');
1087+
expect(notice.text).toContain('[Image omitted');
1088+
expect(notice.text).toContain('"scan.avif"');
1089+
expect(notice.text).toContain('image/avif');
1090+
expect(store.save).toHaveBeenCalledOnce();
1091+
} finally {
1092+
await rm(cacheDir, { recursive: true, force: true });
1093+
}
1094+
});
1095+
10591096
it('sanitizes an attachment file name before materializing it', async () => {
10601097
const id = await createSession(home as string);
10611098
await createMainAgent(id);

0 commit comments

Comments
 (0)