@llmgateway/ai-sdk-provider 3.6.0 → 3.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -2275,6 +2275,29 @@ function getBase64FromDataUrl(dataUrl) {
2275
2275
  }
2276
2276
 
2277
2277
  // src/chat/convert-to-llmgateway-chat-messages.ts
2278
+ var AUDIO_FORMAT_BY_MIME = {
2279
+ "audio/wav": "wav",
2280
+ "audio/wave": "wav",
2281
+ "audio/x-wav": "wav",
2282
+ "audio/mpeg": "mp3",
2283
+ "audio/mp3": "mp3",
2284
+ "audio/mp4": "mp4",
2285
+ "audio/m4a": "m4a",
2286
+ "audio/x-m4a": "m4a",
2287
+ "audio/aac": "aac",
2288
+ "audio/ogg": "ogg",
2289
+ "audio/flac": "flac",
2290
+ "audio/aiff": "aiff",
2291
+ "audio/x-aiff": "aiff",
2292
+ "audio/webm": "webm"
2293
+ };
2294
+ function audioFormatFromMime(mime) {
2295
+ var _a16;
2296
+ if (!mime) return void 0;
2297
+ const lower = (_a16 = mime.toLowerCase().split(";")[0]) == null ? void 0 : _a16.trim();
2298
+ if (!lower) return void 0;
2299
+ return AUDIO_FORMAT_BY_MIME[lower];
2300
+ }
2278
2301
  function getCacheControl(providerOptions) {
2279
2302
  var _a16, _b16, _c;
2280
2303
  const anthropic = providerOptions == null ? void 0 : providerOptions.anthropic;
@@ -2313,7 +2336,7 @@ function convertToLLMGatewayChatMessages(prompt) {
2313
2336
  const messageCacheControl = getCacheControl(providerOptions);
2314
2337
  const contentParts = content.map(
2315
2338
  (part) => {
2316
- var _a17, _b17, _c2, _d, _e, _f;
2339
+ var _a17, _b17, _c2, _d, _e, _f, _g;
2317
2340
  const cacheControl = (_a17 = getCacheControl(part.providerOptions)) != null ? _a17 : messageCacheControl;
2318
2341
  switch (part.type) {
2319
2342
  case "text":
@@ -2338,8 +2361,27 @@ function convertToLLMGatewayChatMessages(prompt) {
2338
2361
  cache_control: cacheControl
2339
2362
  };
2340
2363
  }
2364
+ if ((_c2 = part.mediaType) == null ? void 0 : _c2.startsWith("audio/")) {
2365
+ const format = audioFormatFromMime(part.mediaType);
2366
+ if (format) {
2367
+ const fileUrl = getFileUrl({
2368
+ part,
2369
+ defaultMediaType: part.mediaType
2370
+ });
2371
+ if (fileUrl.startsWith("data:")) {
2372
+ return {
2373
+ type: "input_audio",
2374
+ input_audio: {
2375
+ data: getBase64FromDataUrl(fileUrl),
2376
+ format
2377
+ },
2378
+ cache_control: cacheControl
2379
+ };
2380
+ }
2381
+ }
2382
+ }
2341
2383
  const fileName = String(
2342
- (_f = (_e = (_d = (_c2 = part.providerOptions) == null ? void 0 : _c2.llmgateway) == null ? void 0 : _d.filename) != null ? _e : part.filename) != null ? _f : ""
2384
+ (_g = (_f = (_e = (_d = part.providerOptions) == null ? void 0 : _d.llmgateway) == null ? void 0 : _e.filename) != null ? _f : part.filename) != null ? _g : ""
2343
2385
  );
2344
2386
  const fileData = getFileUrl({
2345
2387
  part,
@@ -3667,13 +3709,19 @@ var LLMGatewayImageModel = class {
3667
3709
  if (options.aspectRatio != null) {
3668
3710
  body.aspect_ratio = options.aspectRatio;
3669
3711
  }
3712
+ if (options.quality != null) {
3713
+ body.quality = options.quality;
3714
+ }
3715
+ const providerOptions = options.providerOptions || {};
3716
+ const llmgatewayOptions = providerOptions.llmgateway || {};
3717
+ const requestBody = __spreadValues(__spreadValues(__spreadValues(__spreadValues({}, body), this.config.extraBody), this.settings.extraBody), llmgatewayOptions);
3670
3718
  const { value: response, responseHeaders } = await postJsonToApi({
3671
3719
  url: this.config.url({
3672
3720
  path: hasFiles ? "/images/edits" : "/images/generations",
3673
3721
  modelId: this.modelId
3674
3722
  }),
3675
3723
  headers: combineHeaders(this.config.headers(), options.headers),
3676
- body,
3724
+ body: requestBody,
3677
3725
  failedResponseHandler: llmgatewayFailedResponseHandler,
3678
3726
  successfulResponseHandler: createJsonResponseHandler(
3679
3727
  LLMGatewayImageResponseSchema
@@ -3732,7 +3780,8 @@ function createLLMGateway(options = {}) {
3732
3780
  provider: "llmgateway.image",
3733
3781
  url: ({ path }) => `${baseURL}${path}`,
3734
3782
  headers: getHeaders,
3735
- fetch: options.fetch
3783
+ fetch: options.fetch,
3784
+ extraBody: options.extraBody
3736
3785
  });
3737
3786
  const createLanguageModel = (modelId, settings) => {
3738
3787
  if (new.target) {