@vargai/gateway 0.3.2 → 0.4.1

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.js CHANGED
@@ -13652,6 +13652,8 @@ var JobResponse = exports_external.object({
13652
13652
  model: exports_external.string(),
13653
13653
  created_at: exports_external.string(),
13654
13654
  completed_at: exports_external.string().optional(),
13655
+ capability: exports_external.string().optional(),
13656
+ source: exports_external.string().optional(),
13655
13657
  output: exports_external.object({
13656
13658
  url: exports_external.string().optional(),
13657
13659
  media_type: exports_external.string(),
@@ -13745,7 +13747,22 @@ var ErrorResponse = exports_external.object({
13745
13747
  provider: exports_external.string().optional(),
13746
13748
  statusCode: exports_external.number().optional()
13747
13749
  });
13748
- // src/client.ts
13750
+ // src/client-v1.ts
13751
+ function normalizeV1Job(job) {
13752
+ const pricing = job.pricing;
13753
+ return {
13754
+ id: job.job_id,
13755
+ status: job.status,
13756
+ output: job.output ? {
13757
+ url: job.output.url,
13758
+ media_type: job.output.media_type,
13759
+ metadata: job.output.metadata
13760
+ } : undefined,
13761
+ pricing,
13762
+ error: job.error
13763
+ };
13764
+ }
13765
+
13749
13766
  class VargGatewayError extends Error {
13750
13767
  statusCode;
13751
13768
  field;
@@ -13759,7 +13776,8 @@ class VargGatewayError extends Error {
13759
13776
  }
13760
13777
  }
13761
13778
 
13762
- class VargClient {
13779
+ class VargClientV1 {
13780
+ version = "v1";
13763
13781
  apiKey;
13764
13782
  baseUrl;
13765
13783
  providerKeys;
@@ -13806,7 +13824,7 @@ class VargClient {
13806
13824
  headers: this.getHeaders(),
13807
13825
  body: JSON.stringify(params)
13808
13826
  });
13809
- return this.handleResponse(response, JobResponse);
13827
+ return normalizeV1Job(await this.handleResponse(response, JobResponse));
13810
13828
  }
13811
13829
  async createImage(params) {
13812
13830
  ImageRequest.parse(params);
@@ -13815,7 +13833,7 @@ class VargClient {
13815
13833
  headers: this.getHeaders(),
13816
13834
  body: JSON.stringify(params)
13817
13835
  });
13818
- return this.handleResponse(response, JobResponse);
13836
+ return normalizeV1Job(await this.handleResponse(response, JobResponse));
13819
13837
  }
13820
13838
  async createSpeech(params) {
13821
13839
  SpeechRequest.parse(params);
@@ -13824,7 +13842,7 @@ class VargClient {
13824
13842
  headers: this.getHeaders(),
13825
13843
  body: JSON.stringify(params)
13826
13844
  });
13827
- return this.handleResponse(response, JobResponse);
13845
+ return normalizeV1Job(await this.handleResponse(response, JobResponse));
13828
13846
  }
13829
13847
  async createMusic(params) {
13830
13848
  MusicRequest.parse(params);
@@ -13833,7 +13851,7 @@ class VargClient {
13833
13851
  headers: this.getHeaders(),
13834
13852
  body: JSON.stringify(params)
13835
13853
  });
13836
- return this.handleResponse(response, JobResponse);
13854
+ return normalizeV1Job(await this.handleResponse(response, JobResponse));
13837
13855
  }
13838
13856
  async createTranscription(params) {
13839
13857
  TranscriptionRequest.parse(params);
@@ -13842,7 +13860,7 @@ class VargClient {
13842
13860
  headers: this.getHeaders(),
13843
13861
  body: JSON.stringify(params)
13844
13862
  });
13845
- return this.handleResponse(response, JobResponse);
13863
+ return normalizeV1Job(await this.handleResponse(response, JobResponse));
13846
13864
  }
13847
13865
  async createSlice(params) {
13848
13866
  FfmpegSliceRequest.parse(params);
@@ -13851,7 +13869,7 @@ class VargClient {
13851
13869
  headers: this.getHeaders(),
13852
13870
  body: JSON.stringify(params)
13853
13871
  });
13854
- return this.handleResponse(response, JobResponse);
13872
+ return normalizeV1Job(await this.handleResponse(response, JobResponse));
13855
13873
  }
13856
13874
  async createFFmpeg(params) {
13857
13875
  FfmpegRequest.parse(params);
@@ -13860,7 +13878,7 @@ class VargClient {
13860
13878
  headers: this.getHeaders(),
13861
13879
  body: JSON.stringify(params)
13862
13880
  });
13863
- return this.handleResponse(response, JobResponse);
13881
+ return normalizeV1Job(await this.handleResponse(response, JobResponse));
13864
13882
  }
13865
13883
  async probe(params) {
13866
13884
  FfmpegProbeRequest.parse(params);
@@ -13951,7 +13969,7 @@ class VargClient {
13951
13969
  method: "GET",
13952
13970
  headers: this.getHeaders()
13953
13971
  });
13954
- return this.handleResponse(response, JobResponse);
13972
+ return normalizeV1Job(await this.handleResponse(response, JobResponse));
13955
13973
  }
13956
13974
  async cancelJob(id) {
13957
13975
  const response = await fetch(`${this.baseUrl}/jobs/${id}`, {
@@ -14035,6 +14053,432 @@ class VargClient {
14035
14053
  }
14036
14054
  throw new VargGatewayError(`job ${id} did not complete within timeout`);
14037
14055
  }
14056
+ async estimate(_params) {
14057
+ throw new VargGatewayError("estimate() is only supported with v2 api (baseUrl /v2). Use POST /v1/estimate directly for v1.", 404);
14058
+ }
14059
+ }
14060
+
14061
+ // src/schemas-v2.ts
14062
+ var VideoRequestV2 = exports_external.object({
14063
+ model: exports_external.string(),
14064
+ prompt: exports_external.string().default(""),
14065
+ duration: exports_external.union([exports_external.number().min(1).max(120), exports_external.string()]).optional(),
14066
+ aspect_ratio: exports_external.string().optional(),
14067
+ files: exports_external.array(exports_external.string().url()).max(10).optional(),
14068
+ provider_options: exports_external.record(exports_external.string(), exports_external.unknown()).optional()
14069
+ });
14070
+ var ImageRequestV2 = exports_external.object({
14071
+ model: exports_external.string(),
14072
+ prompt: exports_external.string().default(""),
14073
+ aspect_ratio: exports_external.string().optional(),
14074
+ files: exports_external.array(exports_external.string().url()).max(10).optional(),
14075
+ provider_options: exports_external.record(exports_external.string(), exports_external.unknown()).optional()
14076
+ });
14077
+ var SpeechRequestV2 = exports_external.object({
14078
+ model: exports_external.string(),
14079
+ text: exports_external.string(),
14080
+ voice: exports_external.string().optional(),
14081
+ provider_options: exports_external.record(exports_external.string(), exports_external.unknown()).optional()
14082
+ });
14083
+ var MusicRequestV2 = exports_external.object({
14084
+ model: exports_external.string(),
14085
+ prompt: exports_external.string(),
14086
+ duration: exports_external.number().optional(),
14087
+ provider_options: exports_external.record(exports_external.string(), exports_external.unknown()).optional()
14088
+ });
14089
+ var TranscriptionRequestV2 = exports_external.object({
14090
+ model: exports_external.string(),
14091
+ audio_url: exports_external.string(),
14092
+ language: exports_external.string().optional(),
14093
+ provider_options: exports_external.record(exports_external.string(), exports_external.unknown()).optional()
14094
+ });
14095
+ var JobStatusV2 = exports_external.enum([
14096
+ "queued",
14097
+ "submitting",
14098
+ "running",
14099
+ "completed",
14100
+ "failed",
14101
+ "cancelled"
14102
+ ]);
14103
+ var BillingTypeV2 = exports_external.enum(["metered", "byok", "x402"]);
14104
+ var JobPricingV2 = exports_external.object({
14105
+ estimated: exports_external.number().nullable(),
14106
+ actual: exports_external.number().nullable(),
14107
+ billing: BillingTypeV2.nullable(),
14108
+ cached: exports_external.boolean().nullable(),
14109
+ billed_units: exports_external.record(exports_external.string(), exports_external.number()).nullable().optional(),
14110
+ pricing_id: exports_external.string().nullable().optional()
14111
+ });
14112
+ var JobOutputItemV2 = exports_external.object({
14113
+ url: exports_external.string().optional(),
14114
+ file_id: exports_external.string().optional(),
14115
+ media_type: exports_external.string().optional(),
14116
+ size_bytes: exports_external.number().optional(),
14117
+ raw: exports_external.unknown().optional(),
14118
+ data: exports_external.unknown().optional()
14119
+ });
14120
+ var JobOutputV2 = exports_external.object({
14121
+ version: exports_external.literal("v1"),
14122
+ outputs: exports_external.array(JobOutputItemV2)
14123
+ });
14124
+ var JobResponseV2 = exports_external.object({
14125
+ id: exports_external.string(),
14126
+ status: JobStatusV2,
14127
+ tool: exports_external.string(),
14128
+ input: exports_external.record(exports_external.string(), exports_external.unknown()),
14129
+ output: JobOutputV2.nullable().optional(),
14130
+ error: exports_external.string().nullable().optional(),
14131
+ estimated_cost_cents: exports_external.number().nullable().optional(),
14132
+ actual_cost_cents: exports_external.number().nullable().optional(),
14133
+ pricing: JobPricingV2.optional(),
14134
+ provider: exports_external.string().nullable().optional(),
14135
+ provider_model: exports_external.string().nullable().optional(),
14136
+ provider_status: exports_external.string().nullable().optional(),
14137
+ created_at: exports_external.string(),
14138
+ started_at: exports_external.string().nullable().optional(),
14139
+ completed_at: exports_external.string().nullable().optional(),
14140
+ urls: exports_external.object({
14141
+ self: exports_external.string(),
14142
+ refresh: exports_external.string(),
14143
+ status: exports_external.string(),
14144
+ cancel: exports_external.string()
14145
+ }).optional()
14146
+ });
14147
+ var EstimateRequestV2 = exports_external.object({
14148
+ model: exports_external.string(),
14149
+ tool: exports_external.string().optional(),
14150
+ capability: exports_external.string().optional()
14151
+ });
14152
+ var EstimateBatchItemV2 = exports_external.object({
14153
+ model: exports_external.string(),
14154
+ capability: exports_external.string().optional(),
14155
+ tool: exports_external.string().optional(),
14156
+ params: exports_external.record(exports_external.string(), exports_external.unknown()).optional()
14157
+ });
14158
+ var EstimateBatchRequestV2 = exports_external.object({
14159
+ items: exports_external.array(EstimateBatchItemV2).min(1).max(100)
14160
+ });
14161
+ var EstimateResponseV2 = exports_external.object({
14162
+ valid: exports_external.boolean(),
14163
+ model: exports_external.string().optional(),
14164
+ tool: exports_external.string().optional(),
14165
+ pricing: exports_external.object({
14166
+ provider_cost_cents: exports_external.number().nullable(),
14167
+ user_price_cents: exports_external.number().nullable(),
14168
+ markup_percent: exports_external.number(),
14169
+ pricing_id: exports_external.string().nullable()
14170
+ }).optional(),
14171
+ code: exports_external.string().optional(),
14172
+ message: exports_external.string().optional(),
14173
+ errors: exports_external.unknown().optional()
14174
+ });
14175
+ var EstimateBatchResponseItemV2 = exports_external.object({
14176
+ capability: exports_external.string(),
14177
+ model: exports_external.string(),
14178
+ credits: exports_external.number(),
14179
+ billing: exports_external.string(),
14180
+ provider: exports_external.string()
14181
+ });
14182
+ var EstimateBatchResponseV2 = exports_external.object({
14183
+ items: exports_external.array(EstimateBatchResponseItemV2),
14184
+ total_credits: exports_external.number()
14185
+ });
14186
+ var FfmpegRequestV2 = exports_external.object({
14187
+ model: exports_external.string().min(1, "'model' is required"),
14188
+ command: exports_external.string(),
14189
+ input_files: exports_external.record(exports_external.string(), exports_external.string().url()),
14190
+ output_files: exports_external.union([exports_external.record(exports_external.string(), exports_external.string()), exports_external.literal("OUTPUT_FOLDER")]),
14191
+ provider_options: exports_external.record(exports_external.string(), exports_external.unknown()).optional()
14192
+ });
14193
+ var FfmpegSliceRequestV2 = exports_external.object({
14194
+ model: exports_external.string().min(1, "'model' is required"),
14195
+ video_url: exports_external.string().url(),
14196
+ codec: exports_external.enum(["copy", "reencode"]).default("copy"),
14197
+ every: exports_external.number().min(0.1).max(3600).optional(),
14198
+ at: exports_external.array(exports_external.number().min(0)).optional(),
14199
+ count: exports_external.number().int().min(2).max(1000).optional(),
14200
+ ranges: exports_external.array(exports_external.object({ start: exports_external.number().min(0), end: exports_external.number().min(0) })).optional(),
14201
+ thumbnails: exports_external.boolean().default(true).optional(),
14202
+ provider_options: exports_external.record(exports_external.string(), exports_external.unknown()).optional()
14203
+ });
14204
+ var FileUploadResponseV2 = exports_external.object({
14205
+ file_id: exports_external.string(),
14206
+ url: exports_external.string(),
14207
+ hash: exports_external.string(),
14208
+ size: exports_external.number(),
14209
+ media_type: exports_external.string(),
14210
+ deduplicated: exports_external.boolean()
14211
+ });
14212
+ var ErrorResponseV2 = exports_external.object({
14213
+ error: exports_external.object({
14214
+ code: exports_external.string().optional(),
14215
+ message: exports_external.string().optional(),
14216
+ field: exports_external.string().optional(),
14217
+ provider: exports_external.string().optional(),
14218
+ errors: exports_external.unknown().optional()
14219
+ }).optional(),
14220
+ code: exports_external.string().optional(),
14221
+ message: exports_external.string().optional()
14222
+ });
14223
+ // src/client-v2.ts
14224
+ function normalizeStatus(status) {
14225
+ if (status === "submitting" || status === "running")
14226
+ return "processing";
14227
+ return status;
14228
+ }
14229
+ function normalizeV2Job(job) {
14230
+ const firstOutput = job.output?.outputs?.[0];
14231
+ const pricing = job.pricing && (job.pricing.estimated != null || job.pricing.actual != null) ? {
14232
+ estimated: job.pricing.estimated ?? 0,
14233
+ actual: job.pricing.actual ?? undefined,
14234
+ billing: job.pricing.billing ?? undefined,
14235
+ cached: job.pricing.cached ?? undefined
14236
+ } : undefined;
14237
+ return {
14238
+ id: job.id,
14239
+ status: normalizeStatus(job.status),
14240
+ output: firstOutput ? {
14241
+ url: firstOutput.url,
14242
+ media_type: firstOutput.media_type,
14243
+ metadata: firstOutput.data ?? firstOutput.raw ?? undefined
14244
+ } : undefined,
14245
+ pricing,
14246
+ error: job.error ?? undefined
14247
+ };
14248
+ }
14249
+
14250
+ class VargClientV2 {
14251
+ version = "v2";
14252
+ apiKey;
14253
+ baseUrl;
14254
+ providerKeys;
14255
+ constructor(config2) {
14256
+ this.apiKey = config2.apiKey;
14257
+ this.baseUrl = config2.baseUrl ?? "https://api.varg.ai/v2";
14258
+ this.providerKeys = config2.providerKeys;
14259
+ }
14260
+ getHeaders() {
14261
+ const headers = {
14262
+ Authorization: `Bearer ${this.apiKey}`,
14263
+ "Content-Type": "application/json"
14264
+ };
14265
+ if (this.providerKeys?.fal)
14266
+ headers["X-Provider-Key-Fal"] = this.providerKeys.fal;
14267
+ if (this.providerKeys?.elevenlabs)
14268
+ headers["X-Provider-Key-ElevenLabs"] = this.providerKeys.elevenlabs;
14269
+ if (this.providerKeys?.higgsfield)
14270
+ headers["X-Provider-Key-Higgsfield"] = this.providerKeys.higgsfield;
14271
+ if (this.providerKeys?.replicate)
14272
+ headers["X-Provider-Key-Replicate"] = this.providerKeys.replicate;
14273
+ if (this.providerKeys?.groq)
14274
+ headers["X-Provider-Key-Groq"] = this.providerKeys.groq;
14275
+ return headers;
14276
+ }
14277
+ async handleResponse(response, schema) {
14278
+ if (!response.ok) {
14279
+ const raw = await response.json().catch(() => null);
14280
+ const err = raw?.error ?? raw;
14281
+ throw new VargGatewayError(err?.message ?? `api returned ${response.status}`, response.status, err?.field, err?.provider);
14282
+ }
14283
+ const data = await response.json();
14284
+ return schema.parse(data);
14285
+ }
14286
+ async createVideo(params) {
14287
+ VideoRequestV2.parse(params);
14288
+ const response = await fetch(`${this.baseUrl}/video`, {
14289
+ method: "POST",
14290
+ headers: this.getHeaders(),
14291
+ body: JSON.stringify(params)
14292
+ });
14293
+ return normalizeV2Job(await this.handleResponse(response, JobResponseV2));
14294
+ }
14295
+ async createImage(params) {
14296
+ ImageRequestV2.parse(params);
14297
+ const response = await fetch(`${this.baseUrl}/image`, {
14298
+ method: "POST",
14299
+ headers: this.getHeaders(),
14300
+ body: JSON.stringify(params)
14301
+ });
14302
+ return normalizeV2Job(await this.handleResponse(response, JobResponseV2));
14303
+ }
14304
+ async createSpeech(params) {
14305
+ SpeechRequestV2.parse(params);
14306
+ const response = await fetch(`${this.baseUrl}/speech`, {
14307
+ method: "POST",
14308
+ headers: this.getHeaders(),
14309
+ body: JSON.stringify(params)
14310
+ });
14311
+ return normalizeV2Job(await this.handleResponse(response, JobResponseV2));
14312
+ }
14313
+ async createMusic(params) {
14314
+ MusicRequestV2.parse(params);
14315
+ const response = await fetch(`${this.baseUrl}/music`, {
14316
+ method: "POST",
14317
+ headers: this.getHeaders(),
14318
+ body: JSON.stringify(params)
14319
+ });
14320
+ return normalizeV2Job(await this.handleResponse(response, JobResponseV2));
14321
+ }
14322
+ async createTranscription(params) {
14323
+ TranscriptionRequestV2.parse(params);
14324
+ const response = await fetch(`${this.baseUrl}/transcription`, {
14325
+ method: "POST",
14326
+ headers: this.getHeaders(),
14327
+ body: JSON.stringify(params)
14328
+ });
14329
+ return normalizeV2Job(await this.handleResponse(response, JobResponseV2));
14330
+ }
14331
+ async createSlice(params) {
14332
+ FfmpegSliceRequestV2.parse(params);
14333
+ const response = await fetch(`${this.baseUrl}/ffmpeg`, {
14334
+ method: "POST",
14335
+ headers: this.getHeaders(),
14336
+ body: JSON.stringify(params)
14337
+ });
14338
+ return normalizeV2Job(await this.handleResponse(response, JobResponseV2));
14339
+ }
14340
+ async createFFmpeg(params) {
14341
+ FfmpegRequestV2.parse(params);
14342
+ const response = await fetch(`${this.baseUrl}/ffmpeg`, {
14343
+ method: "POST",
14344
+ headers: this.getHeaders(),
14345
+ body: JSON.stringify(params)
14346
+ });
14347
+ return normalizeV2Job(await this.handleResponse(response, JobResponseV2));
14348
+ }
14349
+ async probe(_params) {
14350
+ throw new VargGatewayError("probe is not supported in v2 api (no /v2/ffmpeg/probe endpoint). " + "Use v1 gateway or add the route to the api service.", 404);
14351
+ }
14352
+ async uploadFile(file2, mediaType) {
14353
+ const resolvedType = mediaType || (file2 instanceof Blob && file2.type ? file2.type : null) || "application/octet-stream";
14354
+ const headers = {
14355
+ Authorization: `Bearer ${this.apiKey}`,
14356
+ "Content-Type": resolvedType
14357
+ };
14358
+ if (this.providerKeys?.fal)
14359
+ headers["X-Provider-Key-Fal"] = this.providerKeys.fal;
14360
+ if (this.providerKeys?.elevenlabs)
14361
+ headers["X-Provider-Key-ElevenLabs"] = this.providerKeys.elevenlabs;
14362
+ if (this.providerKeys?.higgsfield)
14363
+ headers["X-Provider-Key-Higgsfield"] = this.providerKeys.higgsfield;
14364
+ if (this.providerKeys?.replicate)
14365
+ headers["X-Provider-Key-Replicate"] = this.providerKeys.replicate;
14366
+ if (this.providerKeys?.groq)
14367
+ headers["X-Provider-Key-Groq"] = this.providerKeys.groq;
14368
+ const response = await fetch(`${this.baseUrl}/files`, {
14369
+ method: "POST",
14370
+ headers,
14371
+ body: file2
14372
+ });
14373
+ return this.handleResponse(response, FileUploadResponseV2);
14374
+ }
14375
+ async getJob(id) {
14376
+ const response = await fetch(`${this.baseUrl}/jobs/${id}`, {
14377
+ method: "GET",
14378
+ headers: this.getHeaders()
14379
+ });
14380
+ return normalizeV2Job(await this.handleResponse(response, JobResponseV2));
14381
+ }
14382
+ async cancelJob(id) {
14383
+ const response = await fetch(`${this.baseUrl}/jobs/${id}/cancel`, {
14384
+ method: "POST",
14385
+ headers: this.getHeaders()
14386
+ });
14387
+ if (!response.ok) {
14388
+ const err = await response.json().catch(() => ({}));
14389
+ throw new VargGatewayError(err?.error?.message ?? err?.message ?? `failed to cancel job (${response.status})`, response.status);
14390
+ }
14391
+ }
14392
+ async waitForJob(id, options) {
14393
+ return this.waitForJobPoll(id, options);
14394
+ }
14395
+ async waitForJobPoll(id, options) {
14396
+ const pollIntervalMs = options?.pollIntervalMs ?? 2000;
14397
+ const maxAttempts = options?.maxAttempts ?? 900;
14398
+ for (let i = 0;i < maxAttempts; i++) {
14399
+ const job = await this.getJob(id);
14400
+ if (job.status === "completed" || job.status === "failed" || job.status === "cancelled") {
14401
+ return job;
14402
+ }
14403
+ await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
14404
+ }
14405
+ throw new VargGatewayError(`job ${id} did not complete within timeout`);
14406
+ }
14407
+ async estimate(params) {
14408
+ const response = await fetch(`${this.baseUrl}/estimate`, {
14409
+ method: "POST",
14410
+ headers: this.getHeaders(),
14411
+ body: JSON.stringify(params)
14412
+ });
14413
+ const raw = await response.json().catch(() => null);
14414
+ if (!response.ok) {
14415
+ const err = raw?.error ?? raw;
14416
+ throw new VargGatewayError(err?.message ?? `api returned ${response.status}`, response.status);
14417
+ }
14418
+ if (raw && Array.isArray(raw.items)) {
14419
+ return EstimateBatchResponseV2.parse(raw);
14420
+ }
14421
+ return EstimateResponseV2.parse(raw);
14422
+ }
14423
+ }
14424
+
14425
+ // src/client.ts
14426
+ function detectVersion2(baseUrl) {
14427
+ return /\/v2\/?$/.test(baseUrl) ? "v2" : "v1";
14428
+ }
14429
+
14430
+ class VargClient {
14431
+ backend;
14432
+ version;
14433
+ constructor(config2) {
14434
+ const version2 = config2.version ?? detectVersion2(config2.baseUrl ?? "");
14435
+ this.version = version2;
14436
+ const v2Config = {
14437
+ apiKey: config2.apiKey,
14438
+ baseUrl: config2.baseUrl,
14439
+ providerKeys: config2.providerKeys
14440
+ };
14441
+ this.backend = version2 === "v2" ? new VargClientV2(v2Config) : new VargClientV1(config2);
14442
+ }
14443
+ createVideo(params) {
14444
+ return this.backend.createVideo(params);
14445
+ }
14446
+ createImage(params) {
14447
+ return this.backend.createImage(params);
14448
+ }
14449
+ createSpeech(params) {
14450
+ return this.backend.createSpeech(params);
14451
+ }
14452
+ createMusic(params) {
14453
+ return this.backend.createMusic(params);
14454
+ }
14455
+ createTranscription(params) {
14456
+ return this.backend.createTranscription(params);
14457
+ }
14458
+ createSlice(params) {
14459
+ return this.backend.createSlice(params);
14460
+ }
14461
+ createFFmpeg(params) {
14462
+ return this.backend.createFFmpeg(params);
14463
+ }
14464
+ probe(params) {
14465
+ return this.backend.probe(params);
14466
+ }
14467
+ uploadFile(file2, mediaType) {
14468
+ return this.backend.uploadFile(file2, mediaType);
14469
+ }
14470
+ getJob(id) {
14471
+ return this.backend.getJob(id);
14472
+ }
14473
+ cancelJob(id) {
14474
+ return this.backend.cancelJob(id);
14475
+ }
14476
+ waitForJob(id, options) {
14477
+ return this.backend.waitForJob(id, options);
14478
+ }
14479
+ estimate(params) {
14480
+ return this.backend.estimate(params);
14481
+ }
14038
14482
  }
14039
14483
  // ../../node_modules/.bun/@ai-sdk+provider@3.0.7/node_modules/@ai-sdk/provider/dist/index.mjs
14040
14484
  var marker = "vercel.ai.error";
@@ -14351,6 +14795,19 @@ var UnsupportedFunctionalityError = class extends (_b14 = AISDKError, _a14 = sym
14351
14795
  };
14352
14796
 
14353
14797
  // src/provider.ts
14798
+ async function resolveFiles(client, files) {
14799
+ const urls = [];
14800
+ for (const f of files) {
14801
+ if (f.type === "url") {
14802
+ urls.push(f.url);
14803
+ } else if (f.type === "file") {
14804
+ const fileData = f;
14805
+ const uploaded = await client.uploadFile(new Blob([fileData.data], { type: fileData.mediaType }), fileData.mediaType);
14806
+ urls.push(uploaded.url);
14807
+ }
14808
+ }
14809
+ return client.version === "v2" ? urls : urls.map((url2) => ({ url: url2 }));
14810
+ }
14354
14811
  function createVarg(config2) {
14355
14812
  const client = new VargClient(config2);
14356
14813
  return {
@@ -14362,15 +14819,15 @@ function createVarg(config2) {
14362
14819
  transcriptionModel: (modelId) => new VargTranscriptionModel(modelId, client),
14363
14820
  async slice(params) {
14364
14821
  const job = await client.createSlice(params);
14365
- const completed = job.status === "completed" ? job : await client.waitForJob(job.job_id);
14822
+ const completed = job.status === "completed" ? job : await client.waitForJob(job.id);
14366
14823
  if (completed.status === "failed") {
14367
- throw new Error(`slice job ${completed.job_id} failed: ${completed.error || "unknown"}`);
14824
+ throw new Error(`slice job ${completed.id} failed: ${completed.error || "unknown"}`);
14368
14825
  }
14369
14826
  const metadata = completed.output?.metadata;
14370
14827
  return {
14371
14828
  url: completed.output?.url ?? "",
14372
14829
  segments: metadata?.segments ?? [],
14373
- jobId: completed.job_id
14830
+ jobId: completed.id
14374
14831
  };
14375
14832
  },
14376
14833
  async probe(params) {
@@ -14378,17 +14835,20 @@ function createVarg(config2) {
14378
14835
  },
14379
14836
  async ffmpeg(params) {
14380
14837
  const job = await client.createFFmpeg(params);
14381
- const completed = job.status === "completed" ? job : await client.waitForJob(job.job_id);
14838
+ const completed = job.status === "completed" ? job : await client.waitForJob(job.id);
14382
14839
  if (completed.status === "failed") {
14383
- throw new Error(`ffmpeg job ${completed.job_id} failed: ${completed.error || "unknown"}`);
14840
+ throw new Error(`ffmpeg job ${completed.id} failed: ${completed.error || "unknown"}`);
14384
14841
  }
14385
14842
  return {
14386
14843
  url: completed.output?.url ?? "",
14387
14844
  mediaType: completed.output?.media_type ?? "video/mp4",
14388
- jobId: completed.job_id,
14845
+ jobId: completed.id,
14389
14846
  ...completed.output?.metadata ? { metadata: completed.output.metadata } : {}
14390
14847
  };
14391
14848
  },
14849
+ async estimate(params) {
14850
+ return client.estimate(params);
14851
+ },
14392
14852
  languageModel(modelId) {
14393
14853
  throw new NoSuchModelError({ modelId, modelType: "languageModel" });
14394
14854
  },
@@ -14421,15 +14881,15 @@ async function executeJob(client, capability, params) {
14421
14881
  }
14422
14882
  return {
14423
14883
  data: new Uint8Array(await res2.arrayBuffer()),
14424
- mediaType: job.output.media_type,
14425
- jobId: job.job_id,
14884
+ mediaType: job.output.media_type ?? "application/octet-stream",
14885
+ jobId: job.id,
14426
14886
  ...job.output.metadata ? { metadata: job.output.metadata } : {},
14427
14887
  ...pricing ? { pricing: { ...pricing, cached: true, actual: 0 } } : {}
14428
14888
  };
14429
14889
  }
14430
- const completed = await client.waitForJob(job.job_id);
14890
+ const completed = await client.waitForJob(job.id);
14431
14891
  if (completed.status === "failed") {
14432
- throw new Error(`[${capability}] job ${completed.job_id} failed: ${completed.error || "unknown error"}`);
14892
+ throw new Error(`[${capability}] job ${completed.id} failed: ${completed.error || "unknown error"}`);
14433
14893
  }
14434
14894
  const output = completed.output;
14435
14895
  if (!output?.url) {
@@ -14443,8 +14903,8 @@ async function executeJob(client, capability, params) {
14443
14903
  }
14444
14904
  return {
14445
14905
  data: new Uint8Array(await res.arrayBuffer()),
14446
- mediaType: output.media_type,
14447
- jobId: job.job_id,
14906
+ mediaType: output.media_type ?? "application/octet-stream",
14907
+ jobId: job.id,
14448
14908
  ...output.metadata ? { metadata: output.metadata } : {},
14449
14909
  ...finalPricing ? { pricing: finalPricing } : {}
14450
14910
  };
@@ -14471,16 +14931,7 @@ class VargVideoModel {
14471
14931
  if (options.aspectRatio)
14472
14932
  params.aspect_ratio = options.aspectRatio;
14473
14933
  if (options.files && options.files.length > 0) {
14474
- const fileUrls = [];
14475
- for (const f of options.files) {
14476
- if (f.type === "url") {
14477
- fileUrls.push({ url: f.url });
14478
- } else if (f.type === "file") {
14479
- const fileData = f;
14480
- const uploaded = await this.client.uploadFile(new Blob([fileData.data], { type: fileData.mediaType }), fileData.mediaType);
14481
- fileUrls.push({ url: uploaded.url });
14482
- }
14483
- }
14934
+ const fileUrls = await resolveFiles(this.client, options.files);
14484
14935
  if (fileUrls.length > 0) {
14485
14936
  params.files = fileUrls;
14486
14937
  }
@@ -14521,16 +14972,7 @@ class VargImageModel {
14521
14972
  if (options.aspectRatio)
14522
14973
  params.aspect_ratio = options.aspectRatio;
14523
14974
  if (options.files && options.files.length > 0) {
14524
- const fileUrls = [];
14525
- for (const f of options.files) {
14526
- if (f.type === "url") {
14527
- fileUrls.push({ url: f.url });
14528
- } else if (f.type === "file") {
14529
- const fileData = f;
14530
- const uploaded = await this.client.uploadFile(new Blob([fileData.data], { type: fileData.mediaType }), fileData.mediaType);
14531
- fileUrls.push({ url: uploaded.url });
14532
- }
14533
- }
14975
+ const fileUrls = await resolveFiles(this.client, options.files);
14534
14976
  if (fileUrls.length > 0) {
14535
14977
  params.files = fileUrls;
14536
14978
  }
@@ -14638,9 +15080,9 @@ class VargTranscriptionModel {
14638
15080
  ...options.providerOptions?.varg?.language ? { language: options.providerOptions.varg.language } : {},
14639
15081
  ...options.providerOptions?.varg ? { provider_options: options.providerOptions.varg } : {}
14640
15082
  });
14641
- const completed = await this.client.waitForJob(job.job_id);
15083
+ const completed = await this.client.waitForJob(job.id);
14642
15084
  if (completed.status === "failed") {
14643
- throw new Error(`[transcription] job ${completed.job_id} failed: ${completed.error || "unknown error"}`);
15085
+ throw new Error(`[transcription] job ${completed.id} failed: ${completed.error || "unknown error"}`);
14644
15086
  }
14645
15087
  const metadata = completed.output?.metadata;
14646
15088
  const text = metadata?.text ?? "";
@@ -14667,20 +15109,40 @@ class VargTranscriptionModel {
14667
15109
  export {
14668
15110
  varg_provider as varg,
14669
15111
  createVarg,
15112
+ VideoRequestV2,
14670
15113
  VideoRequest as VideoRequestSchema,
14671
15114
  VargGatewayError,
14672
15115
  VargClient,
15116
+ TranscriptionRequestV2,
14673
15117
  TranscriptionRequest as TranscriptionRequestSchema,
15118
+ SpeechRequestV2,
14674
15119
  SpeechRequest as SpeechRequestSchema,
15120
+ MusicRequestV2,
14675
15121
  MusicRequest as MusicRequestSchema,
15122
+ JobStatusV2,
14676
15123
  JobStatus as JobStatusSchema,
15124
+ JobResponseV2,
14677
15125
  JobResponse as JobResponseSchema,
15126
+ JobPricingV2,
15127
+ JobOutputV2,
15128
+ JobOutputItemV2,
15129
+ ImageRequestV2,
14678
15130
  ImageRequest as ImageRequestSchema,
15131
+ FileUploadResponseV2,
14679
15132
  FileUploadResponse as FileUploadResponseSchema,
14680
15133
  FileInput as FileInputSchema,
15134
+ FfmpegSliceRequestV2,
14681
15135
  FfmpegSliceRequest as FfmpegSliceRequestSchema,
15136
+ FfmpegRequestV2,
14682
15137
  FfmpegRequest as FfmpegRequestSchema,
14683
15138
  FfmpegProbeResponse as FfmpegProbeResponseSchema,
14684
15139
  FfmpegProbeRequest as FfmpegProbeRequestSchema,
15140
+ EstimateResponseV2,
15141
+ EstimateRequestV2,
15142
+ EstimateBatchResponseV2,
15143
+ EstimateBatchResponseItemV2,
15144
+ EstimateBatchRequestV2,
15145
+ EstimateBatchItemV2,
15146
+ ErrorResponseV2,
14685
15147
  ErrorResponse as ErrorResponseSchema
14686
15148
  };