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