fix: preserve synthetic transcript attachment order

This commit is contained in:
Eulices Lopez 2026-03-18 01:52:58 -04:00 committed by Eulices Lopez
parent bac89c2ec8
commit d6648e77bc
2 changed files with 26 additions and 0 deletions

View File

@ -532,6 +532,7 @@ export async function applyMediaUnderstanding(params: {
(output) => !audioOutputAttachmentIndexes.has(output.attachmentIndex),
);
outputs.push(...syntheticSkippedAudioOutputs);
outputs.sort((left, right) => left.attachmentIndex - right.attachmentIndex);
if (decisions.length > 0) {
ctx.MediaUnderstandingDecisions = [...(ctx.MediaUnderstandingDecisions ?? []), ...decisions];

View File

@ -88,4 +88,29 @@ describe("formatMediaUnderstandingBody", () => {
});
expect(body).toBe("[Image]\nDescription:\na cat");
});
it("labels audio transcripts by their attachment order", () => {
const body = formatMediaUnderstandingBody({
outputs: [
{
kind: "audio.transcription",
attachmentIndex: 0,
text: "first clip was silent",
provider: "openclaw",
},
{
kind: "audio.transcription",
attachmentIndex: 1,
text: "second clip has speech",
provider: "groq",
},
],
});
expect(body).toBe(
[
"[Audio 1/2]\nTranscript:\nfirst clip was silent",
"[Audio 2/2]\nTranscript:\nsecond clip has speech",
].join("\n\n"),
);
});
});