File size: 1,195 Bytes
e43a4a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import test from "node:test";
import assert from "node:assert/strict";
import { InMemoryMediaStore } from "../src/services/mediaStore.js";
import { createResponseNormalizationService } from "../src/services/responseNormalizationService.js";

test("adds proxy URLs for audio and data-url image outputs", () => {
  const mediaStore = new InMemoryMediaStore({ ttlSeconds: 3600 });
  const service = createResponseNormalizationService({ mediaStore });

  const normalized = service.normalize({
    choices: [
      {
        message: {
          audio: {
            data: "ZmFrZS1hdWRpbw=="
          },
          content: [
            {
              type: "image_url",
              image_url: {
                url: "data:image/png;base64,aW1hZ2U="
              }
            }
          ]
        }
      }
    ]
  }, {
    publicBaseUrl: "http://localhost:3000",
    audioFormat: "mp3",
    exposeMediaUrls: true
  });

  assert.match(normalized.choices[0].message.audio.url, /^http:\/\/localhost:3000\/v1\/media\//);
  assert.match(normalized.choices[0].message.content[0].image_url.proxy_url, /^http:\/\/localhost:3000\/v1\/media\//);
  assert.equal(normalized.proxy.media.length, 2);
});