@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.d.mts CHANGED
@@ -133,7 +133,9 @@ type LLMGatewayCompletionSettings = {
133
133
  } & LLMGatewaySharedSettings;
134
134
 
135
135
  type LLMGatewayImageModelId = string;
136
- type LLMGatewayImageSettings = {};
136
+ type LLMGatewayImageSettings = {
137
+ extraBody?: Record<string, unknown>;
138
+ };
137
139
 
138
140
  type LLMGatewayChatConfig = {
139
141
  provider: string;
@@ -191,6 +193,10 @@ type LLMGatewayImageConfig = {
191
193
  path: string;
192
194
  }) => string;
193
195
  fetch?: typeof fetch;
196
+ extraBody?: Record<string, unknown>;
197
+ };
198
+ type LLMGatewayImageModelCallOptions = ImageModelV3CallOptions & {
199
+ quality?: string;
194
200
  };
195
201
  declare class LLMGatewayImageModel implements ImageModelV3 {
196
202
  readonly specificationVersion: "v3";
@@ -200,7 +206,7 @@ declare class LLMGatewayImageModel implements ImageModelV3 {
200
206
  readonly settings: LLMGatewayImageSettings;
201
207
  private readonly config;
202
208
  constructor(modelId: LLMGatewayImageModelId, settings: LLMGatewayImageSettings, config: LLMGatewayImageConfig);
203
- doGenerate(options: ImageModelV3CallOptions): Promise<{
209
+ doGenerate(options: LLMGatewayImageModelCallOptions): Promise<{
204
210
  images: Array<string>;
205
211
  warnings: Array<SharedV3Warning>;
206
212
  response: {
package/dist/index.d.ts CHANGED
@@ -133,7 +133,9 @@ type LLMGatewayCompletionSettings = {
133
133
  } & LLMGatewaySharedSettings;
134
134
 
135
135
  type LLMGatewayImageModelId = string;
136
- type LLMGatewayImageSettings = {};
136
+ type LLMGatewayImageSettings = {
137
+ extraBody?: Record<string, unknown>;
138
+ };
137
139
 
138
140
  type LLMGatewayChatConfig = {
139
141
  provider: string;
@@ -191,6 +193,10 @@ type LLMGatewayImageConfig = {
191
193
  path: string;
192
194
  }) => string;
193
195
  fetch?: typeof fetch;
196
+ extraBody?: Record<string, unknown>;
197
+ };
198
+ type LLMGatewayImageModelCallOptions = ImageModelV3CallOptions & {
199
+ quality?: string;
194
200
  };
195
201
  declare class LLMGatewayImageModel implements ImageModelV3 {
196
202
  readonly specificationVersion: "v3";
@@ -200,7 +206,7 @@ declare class LLMGatewayImageModel implements ImageModelV3 {
200
206
  readonly settings: LLMGatewayImageSettings;
201
207
  private readonly config;
202
208
  constructor(modelId: LLMGatewayImageModelId, settings: LLMGatewayImageSettings, config: LLMGatewayImageConfig);
203
- doGenerate(options: ImageModelV3CallOptions): Promise<{
209
+ doGenerate(options: LLMGatewayImageModelCallOptions): Promise<{
204
210
  images: Array<string>;
205
211
  warnings: Array<SharedV3Warning>;
206
212
  response: {
package/dist/index.js CHANGED
@@ -2308,6 +2308,29 @@ function getBase64FromDataUrl(dataUrl) {
2308
2308
  }
2309
2309
 
2310
2310
  // src/chat/convert-to-llmgateway-chat-messages.ts
2311
+ var AUDIO_FORMAT_BY_MIME = {
2312
+ "audio/wav": "wav",
2313
+ "audio/wave": "wav",
2314
+ "audio/x-wav": "wav",
2315
+ "audio/mpeg": "mp3",
2316
+ "audio/mp3": "mp3",
2317
+ "audio/mp4": "mp4",
2318
+ "audio/m4a": "m4a",
2319
+ "audio/x-m4a": "m4a",
2320
+ "audio/aac": "aac",
2321
+ "audio/ogg": "ogg",
2322
+ "audio/flac": "flac",
2323
+ "audio/aiff": "aiff",
2324
+ "audio/x-aiff": "aiff",
2325
+ "audio/webm": "webm"
2326
+ };
2327
+ function audioFormatFromMime(mime) {
2328
+ var _a16;
2329
+ if (!mime) return void 0;
2330
+ const lower = (_a16 = mime.toLowerCase().split(";")[0]) == null ? void 0 : _a16.trim();
2331
+ if (!lower) return void 0;
2332
+ return AUDIO_FORMAT_BY_MIME[lower];
2333
+ }
2311
2334
  function getCacheControl(providerOptions) {
2312
2335
  var _a16, _b16, _c;
2313
2336
  const anthropic = providerOptions == null ? void 0 : providerOptions.anthropic;
@@ -2346,7 +2369,7 @@ function convertToLLMGatewayChatMessages(prompt) {
2346
2369
  const messageCacheControl = getCacheControl(providerOptions);
2347
2370
  const contentParts = content.map(
2348
2371
  (part) => {
2349
- var _a17, _b17, _c2, _d, _e, _f;
2372
+ var _a17, _b17, _c2, _d, _e, _f, _g;
2350
2373
  const cacheControl = (_a17 = getCacheControl(part.providerOptions)) != null ? _a17 : messageCacheControl;
2351
2374
  switch (part.type) {
2352
2375
  case "text":
@@ -2371,8 +2394,27 @@ function convertToLLMGatewayChatMessages(prompt) {
2371
2394
  cache_control: cacheControl
2372
2395
  };
2373
2396
  }
2397
+ if ((_c2 = part.mediaType) == null ? void 0 : _c2.startsWith("audio/")) {
2398
+ const format = audioFormatFromMime(part.mediaType);
2399
+ if (format) {
2400
+ const fileUrl = getFileUrl({
2401
+ part,
2402
+ defaultMediaType: part.mediaType
2403
+ });
2404
+ if (fileUrl.startsWith("data:")) {
2405
+ return {
2406
+ type: "input_audio",
2407
+ input_audio: {
2408
+ data: getBase64FromDataUrl(fileUrl),
2409
+ format
2410
+ },
2411
+ cache_control: cacheControl
2412
+ };
2413
+ }
2414
+ }
2415
+ }
2374
2416
  const fileName = String(
2375
- (_f = (_e = (_d = (_c2 = part.providerOptions) == null ? void 0 : _c2.llmgateway) == null ? void 0 : _d.filename) != null ? _e : part.filename) != null ? _f : ""
2417
+ (_g = (_f = (_e = (_d = part.providerOptions) == null ? void 0 : _d.llmgateway) == null ? void 0 : _e.filename) != null ? _f : part.filename) != null ? _g : ""
2376
2418
  );
2377
2419
  const fileData = getFileUrl({
2378
2420
  part,
@@ -3700,13 +3742,19 @@ var LLMGatewayImageModel = class {
3700
3742
  if (options.aspectRatio != null) {
3701
3743
  body.aspect_ratio = options.aspectRatio;
3702
3744
  }
3745
+ if (options.quality != null) {
3746
+ body.quality = options.quality;
3747
+ }
3748
+ const providerOptions = options.providerOptions || {};
3749
+ const llmgatewayOptions = providerOptions.llmgateway || {};
3750
+ const requestBody = __spreadValues(__spreadValues(__spreadValues(__spreadValues({}, body), this.config.extraBody), this.settings.extraBody), llmgatewayOptions);
3703
3751
  const { value: response, responseHeaders } = await postJsonToApi({
3704
3752
  url: this.config.url({
3705
3753
  path: hasFiles ? "/images/edits" : "/images/generations",
3706
3754
  modelId: this.modelId
3707
3755
  }),
3708
3756
  headers: combineHeaders(this.config.headers(), options.headers),
3709
- body,
3757
+ body: requestBody,
3710
3758
  failedResponseHandler: llmgatewayFailedResponseHandler,
3711
3759
  successfulResponseHandler: createJsonResponseHandler(
3712
3760
  LLMGatewayImageResponseSchema
@@ -3765,7 +3813,8 @@ function createLLMGateway(options = {}) {
3765
3813
  provider: "llmgateway.image",
3766
3814
  url: ({ path }) => `${baseURL}${path}`,
3767
3815
  headers: getHeaders,
3768
- fetch: options.fetch
3816
+ fetch: options.fetch,
3817
+ extraBody: options.extraBody
3769
3818
  });
3770
3819
  const createLanguageModel = (modelId, settings) => {
3771
3820
  if (new.target) {