@vargai/gateway 0.3.1 → 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 +514 -35
- package/dist/provider.d.ts +25 -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 +2 -2
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(),
|
|
@@ -13696,8 +13698,26 @@ var FfmpegSliceRequest = exports_external.object({
|
|
|
13696
13698
|
at: exports_external.array(exports_external.number().min(0)).optional(),
|
|
13697
13699
|
count: exports_external.number().int().min(2).max(1000).optional(),
|
|
13698
13700
|
ranges: exports_external.array(exports_external.object({ start: exports_external.number().min(0), end: exports_external.number().min(0) })).optional(),
|
|
13701
|
+
thumbnails: exports_external.boolean().default(true).optional(),
|
|
13699
13702
|
provider_options: exports_external.record(exports_external.string(), exports_external.unknown()).optional()
|
|
13700
13703
|
}).refine((d) => [d.every, d.at, d.count, d.ranges].filter((v) => v !== undefined).length === 1, { message: "exactly one of every, at, count, or ranges must be provided" });
|
|
13704
|
+
var FfmpegTrimRequest = exports_external.object({
|
|
13705
|
+
url: exports_external.string(),
|
|
13706
|
+
start: exports_external.number().min(0),
|
|
13707
|
+
end: exports_external.number().min(0).optional(),
|
|
13708
|
+
duration: exports_external.number().min(0).optional(),
|
|
13709
|
+
precise: exports_external.boolean().default(false)
|
|
13710
|
+
}).refine((d) => d.end !== undefined !== (d.duration !== undefined), {
|
|
13711
|
+
message: "exactly one of end or duration must be provided"
|
|
13712
|
+
});
|
|
13713
|
+
var FfmpegResizeRequest = exports_external.object({
|
|
13714
|
+
url: exports_external.string(),
|
|
13715
|
+
width: exports_external.number().int().min(1).optional(),
|
|
13716
|
+
height: exports_external.number().int().min(1).optional(),
|
|
13717
|
+
fit: exports_external.enum(["contain", "cover", "stretch"]).default("cover")
|
|
13718
|
+
}).refine((d) => d.width !== undefined || d.height !== undefined, {
|
|
13719
|
+
message: "at least one of width or height must be provided"
|
|
13720
|
+
});
|
|
13701
13721
|
var FfmpegProbeRequest = exports_external.object({
|
|
13702
13722
|
url: exports_external.string()
|
|
13703
13723
|
});
|
|
@@ -13727,7 +13747,22 @@ var ErrorResponse = exports_external.object({
|
|
|
13727
13747
|
provider: exports_external.string().optional(),
|
|
13728
13748
|
statusCode: exports_external.number().optional()
|
|
13729
13749
|
});
|
|
13730
|
-
// 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
|
+
|
|
13731
13766
|
class VargGatewayError extends Error {
|
|
13732
13767
|
statusCode;
|
|
13733
13768
|
field;
|
|
@@ -13741,7 +13776,7 @@ class VargGatewayError extends Error {
|
|
|
13741
13776
|
}
|
|
13742
13777
|
}
|
|
13743
13778
|
|
|
13744
|
-
class
|
|
13779
|
+
class VargClientV1 {
|
|
13745
13780
|
apiKey;
|
|
13746
13781
|
baseUrl;
|
|
13747
13782
|
providerKeys;
|
|
@@ -13788,7 +13823,7 @@ class VargClient {
|
|
|
13788
13823
|
headers: this.getHeaders(),
|
|
13789
13824
|
body: JSON.stringify(params)
|
|
13790
13825
|
});
|
|
13791
|
-
return this.handleResponse(response, JobResponse);
|
|
13826
|
+
return normalizeV1Job(await this.handleResponse(response, JobResponse));
|
|
13792
13827
|
}
|
|
13793
13828
|
async createImage(params) {
|
|
13794
13829
|
ImageRequest.parse(params);
|
|
@@ -13797,7 +13832,7 @@ class VargClient {
|
|
|
13797
13832
|
headers: this.getHeaders(),
|
|
13798
13833
|
body: JSON.stringify(params)
|
|
13799
13834
|
});
|
|
13800
|
-
return this.handleResponse(response, JobResponse);
|
|
13835
|
+
return normalizeV1Job(await this.handleResponse(response, JobResponse));
|
|
13801
13836
|
}
|
|
13802
13837
|
async createSpeech(params) {
|
|
13803
13838
|
SpeechRequest.parse(params);
|
|
@@ -13806,7 +13841,7 @@ class VargClient {
|
|
|
13806
13841
|
headers: this.getHeaders(),
|
|
13807
13842
|
body: JSON.stringify(params)
|
|
13808
13843
|
});
|
|
13809
|
-
return this.handleResponse(response, JobResponse);
|
|
13844
|
+
return normalizeV1Job(await this.handleResponse(response, JobResponse));
|
|
13810
13845
|
}
|
|
13811
13846
|
async createMusic(params) {
|
|
13812
13847
|
MusicRequest.parse(params);
|
|
@@ -13815,7 +13850,7 @@ class VargClient {
|
|
|
13815
13850
|
headers: this.getHeaders(),
|
|
13816
13851
|
body: JSON.stringify(params)
|
|
13817
13852
|
});
|
|
13818
|
-
return this.handleResponse(response, JobResponse);
|
|
13853
|
+
return normalizeV1Job(await this.handleResponse(response, JobResponse));
|
|
13819
13854
|
}
|
|
13820
13855
|
async createTranscription(params) {
|
|
13821
13856
|
TranscriptionRequest.parse(params);
|
|
@@ -13824,7 +13859,7 @@ class VargClient {
|
|
|
13824
13859
|
headers: this.getHeaders(),
|
|
13825
13860
|
body: JSON.stringify(params)
|
|
13826
13861
|
});
|
|
13827
|
-
return this.handleResponse(response, JobResponse);
|
|
13862
|
+
return normalizeV1Job(await this.handleResponse(response, JobResponse));
|
|
13828
13863
|
}
|
|
13829
13864
|
async createSlice(params) {
|
|
13830
13865
|
FfmpegSliceRequest.parse(params);
|
|
@@ -13833,7 +13868,7 @@ class VargClient {
|
|
|
13833
13868
|
headers: this.getHeaders(),
|
|
13834
13869
|
body: JSON.stringify(params)
|
|
13835
13870
|
});
|
|
13836
|
-
return this.handleResponse(response, JobResponse);
|
|
13871
|
+
return normalizeV1Job(await this.handleResponse(response, JobResponse));
|
|
13837
13872
|
}
|
|
13838
13873
|
async createFFmpeg(params) {
|
|
13839
13874
|
FfmpegRequest.parse(params);
|
|
@@ -13842,7 +13877,7 @@ class VargClient {
|
|
|
13842
13877
|
headers: this.getHeaders(),
|
|
13843
13878
|
body: JSON.stringify(params)
|
|
13844
13879
|
});
|
|
13845
|
-
return this.handleResponse(response, JobResponse);
|
|
13880
|
+
return normalizeV1Job(await this.handleResponse(response, JobResponse));
|
|
13846
13881
|
}
|
|
13847
13882
|
async probe(params) {
|
|
13848
13883
|
FfmpegProbeRequest.parse(params);
|
|
@@ -13933,7 +13968,7 @@ class VargClient {
|
|
|
13933
13968
|
method: "GET",
|
|
13934
13969
|
headers: this.getHeaders()
|
|
13935
13970
|
});
|
|
13936
|
-
return this.handleResponse(response, JobResponse);
|
|
13971
|
+
return normalizeV1Job(await this.handleResponse(response, JobResponse));
|
|
13937
13972
|
}
|
|
13938
13973
|
async cancelJob(id) {
|
|
13939
13974
|
const response = await fetch(`${this.baseUrl}/jobs/${id}`, {
|
|
@@ -13953,7 +13988,7 @@ class VargClient {
|
|
|
13953
13988
|
}
|
|
13954
13989
|
}
|
|
13955
13990
|
async waitForJobSSE(id, options) {
|
|
13956
|
-
const timeoutMs = (options?.maxAttempts ??
|
|
13991
|
+
const timeoutMs = (options?.maxAttempts ?? 900) * (options?.pollIntervalMs ?? 2000);
|
|
13957
13992
|
const response = await fetch(`${this.baseUrl}/jobs/${id}/stream`, {
|
|
13958
13993
|
method: "GET",
|
|
13959
13994
|
headers: {
|
|
@@ -14007,7 +14042,357 @@ class VargClient {
|
|
|
14007
14042
|
}
|
|
14008
14043
|
async waitForJobPoll(id, options) {
|
|
14009
14044
|
const pollIntervalMs = options?.pollIntervalMs ?? 2000;
|
|
14010
|
-
const maxAttempts = options?.maxAttempts ??
|
|
14045
|
+
const maxAttempts = options?.maxAttempts ?? 900;
|
|
14046
|
+
for (let i = 0;i < maxAttempts; i++) {
|
|
14047
|
+
const job = await this.getJob(id);
|
|
14048
|
+
if (job.status === "completed" || job.status === "failed" || job.status === "cancelled") {
|
|
14049
|
+
return job;
|
|
14050
|
+
}
|
|
14051
|
+
await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
|
|
14052
|
+
}
|
|
14053
|
+
throw new VargGatewayError(`job ${id} did not complete within timeout`);
|
|
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;
|
|
14011
14396
|
for (let i = 0;i < maxAttempts; i++) {
|
|
14012
14397
|
const job = await this.getJob(id);
|
|
14013
14398
|
if (job.status === "completed" || job.status === "failed" || job.status === "cancelled") {
|
|
@@ -14017,6 +14402,79 @@ class VargClient {
|
|
|
14017
14402
|
}
|
|
14018
14403
|
throw new VargGatewayError(`job ${id} did not complete within timeout`);
|
|
14019
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
|
+
}
|
|
14020
14478
|
}
|
|
14021
14479
|
// ../../node_modules/.bun/@ai-sdk+provider@3.0.7/node_modules/@ai-sdk/provider/dist/index.mjs
|
|
14022
14480
|
var marker = "vercel.ai.error";
|
|
@@ -14344,15 +14802,15 @@ function createVarg(config2) {
|
|
|
14344
14802
|
transcriptionModel: (modelId) => new VargTranscriptionModel(modelId, client),
|
|
14345
14803
|
async slice(params) {
|
|
14346
14804
|
const job = await client.createSlice(params);
|
|
14347
|
-
const completed = job.status === "completed" ? job : await client.waitForJob(job.
|
|
14805
|
+
const completed = job.status === "completed" ? job : await client.waitForJob(job.id);
|
|
14348
14806
|
if (completed.status === "failed") {
|
|
14349
|
-
throw new Error(`slice job ${completed.
|
|
14807
|
+
throw new Error(`slice job ${completed.id} failed: ${completed.error || "unknown"}`);
|
|
14350
14808
|
}
|
|
14351
14809
|
const metadata = completed.output?.metadata;
|
|
14352
14810
|
return {
|
|
14353
14811
|
url: completed.output?.url ?? "",
|
|
14354
14812
|
segments: metadata?.segments ?? [],
|
|
14355
|
-
jobId: completed.
|
|
14813
|
+
jobId: completed.id
|
|
14356
14814
|
};
|
|
14357
14815
|
},
|
|
14358
14816
|
async probe(params) {
|
|
@@ -14360,17 +14818,20 @@ function createVarg(config2) {
|
|
|
14360
14818
|
},
|
|
14361
14819
|
async ffmpeg(params) {
|
|
14362
14820
|
const job = await client.createFFmpeg(params);
|
|
14363
|
-
const completed = job.status === "completed" ? job : await client.waitForJob(job.
|
|
14821
|
+
const completed = job.status === "completed" ? job : await client.waitForJob(job.id);
|
|
14364
14822
|
if (completed.status === "failed") {
|
|
14365
|
-
throw new Error(`ffmpeg job ${completed.
|
|
14823
|
+
throw new Error(`ffmpeg job ${completed.id} failed: ${completed.error || "unknown"}`);
|
|
14366
14824
|
}
|
|
14367
14825
|
return {
|
|
14368
14826
|
url: completed.output?.url ?? "",
|
|
14369
14827
|
mediaType: completed.output?.media_type ?? "video/mp4",
|
|
14370
|
-
jobId: completed.
|
|
14371
|
-
metadata: completed.output
|
|
14828
|
+
jobId: completed.id,
|
|
14829
|
+
...completed.output?.metadata ? { metadata: completed.output.metadata } : {}
|
|
14372
14830
|
};
|
|
14373
14831
|
},
|
|
14832
|
+
async estimate(params) {
|
|
14833
|
+
return client.estimate(params);
|
|
14834
|
+
},
|
|
14374
14835
|
languageModel(modelId) {
|
|
14375
14836
|
throw new NoSuchModelError({ modelId, modelType: "languageModel" });
|
|
14376
14837
|
},
|
|
@@ -14403,15 +14864,15 @@ async function executeJob(client, capability, params) {
|
|
|
14403
14864
|
}
|
|
14404
14865
|
return {
|
|
14405
14866
|
data: new Uint8Array(await res2.arrayBuffer()),
|
|
14406
|
-
mediaType: job.output.media_type,
|
|
14407
|
-
jobId: job.
|
|
14408
|
-
metadata: job.output.metadata,
|
|
14409
|
-
pricing
|
|
14867
|
+
mediaType: job.output.media_type ?? "application/octet-stream",
|
|
14868
|
+
jobId: job.id,
|
|
14869
|
+
...job.output.metadata ? { metadata: job.output.metadata } : {},
|
|
14870
|
+
...pricing ? { pricing: { ...pricing, cached: true, actual: 0 } } : {}
|
|
14410
14871
|
};
|
|
14411
14872
|
}
|
|
14412
|
-
const completed = await client.waitForJob(job.
|
|
14873
|
+
const completed = await client.waitForJob(job.id);
|
|
14413
14874
|
if (completed.status === "failed") {
|
|
14414
|
-
throw new Error(`[${capability}] job ${completed.
|
|
14875
|
+
throw new Error(`[${capability}] job ${completed.id} failed: ${completed.error || "unknown error"}`);
|
|
14415
14876
|
}
|
|
14416
14877
|
const output = completed.output;
|
|
14417
14878
|
if (!output?.url) {
|
|
@@ -14425,10 +14886,10 @@ async function executeJob(client, capability, params) {
|
|
|
14425
14886
|
}
|
|
14426
14887
|
return {
|
|
14427
14888
|
data: new Uint8Array(await res.arrayBuffer()),
|
|
14428
|
-
mediaType: output.media_type,
|
|
14429
|
-
jobId: job.
|
|
14430
|
-
metadata: output.metadata,
|
|
14431
|
-
pricing: finalPricing
|
|
14889
|
+
mediaType: output.media_type ?? "application/octet-stream",
|
|
14890
|
+
jobId: job.id,
|
|
14891
|
+
...output.metadata ? { metadata: output.metadata } : {},
|
|
14892
|
+
...finalPricing ? { pricing: finalPricing } : {}
|
|
14432
14893
|
};
|
|
14433
14894
|
}
|
|
14434
14895
|
var varg_provider = createVarg({ apiKey: process.env.VARG_API_KEY ?? "" });
|
|
@@ -14620,9 +15081,9 @@ class VargTranscriptionModel {
|
|
|
14620
15081
|
...options.providerOptions?.varg?.language ? { language: options.providerOptions.varg.language } : {},
|
|
14621
15082
|
...options.providerOptions?.varg ? { provider_options: options.providerOptions.varg } : {}
|
|
14622
15083
|
});
|
|
14623
|
-
const completed = await this.client.waitForJob(job.
|
|
15084
|
+
const completed = await this.client.waitForJob(job.id);
|
|
14624
15085
|
if (completed.status === "failed") {
|
|
14625
|
-
throw new Error(`[transcription] job ${completed.
|
|
15086
|
+
throw new Error(`[transcription] job ${completed.id} failed: ${completed.error || "unknown error"}`);
|
|
14626
15087
|
}
|
|
14627
15088
|
const metadata = completed.output?.metadata;
|
|
14628
15089
|
const text = metadata?.text ?? "";
|
|
@@ -14640,31 +15101,49 @@ class VargTranscriptionModel {
|
|
|
14640
15101
|
warnings,
|
|
14641
15102
|
response: {
|
|
14642
15103
|
timestamp: new Date,
|
|
14643
|
-
modelId: this.modelId
|
|
14644
|
-
headers: undefined,
|
|
14645
|
-
body: metadata
|
|
15104
|
+
modelId: this.modelId
|
|
14646
15105
|
},
|
|
14647
|
-
|
|
15106
|
+
...metadata?.words ? { providerMetadata: { varg: { words: metadata.words } } } : {}
|
|
14648
15107
|
};
|
|
14649
15108
|
}
|
|
14650
15109
|
}
|
|
14651
15110
|
export {
|
|
14652
15111
|
varg_provider as varg,
|
|
14653
15112
|
createVarg,
|
|
15113
|
+
VideoRequestV2,
|
|
14654
15114
|
VideoRequest as VideoRequestSchema,
|
|
14655
15115
|
VargGatewayError,
|
|
14656
15116
|
VargClient,
|
|
15117
|
+
TranscriptionRequestV2,
|
|
14657
15118
|
TranscriptionRequest as TranscriptionRequestSchema,
|
|
15119
|
+
SpeechRequestV2,
|
|
14658
15120
|
SpeechRequest as SpeechRequestSchema,
|
|
15121
|
+
MusicRequestV2,
|
|
14659
15122
|
MusicRequest as MusicRequestSchema,
|
|
15123
|
+
JobStatusV2,
|
|
14660
15124
|
JobStatus as JobStatusSchema,
|
|
15125
|
+
JobResponseV2,
|
|
14661
15126
|
JobResponse as JobResponseSchema,
|
|
15127
|
+
JobPricingV2,
|
|
15128
|
+
JobOutputV2,
|
|
15129
|
+
JobOutputItemV2,
|
|
15130
|
+
ImageRequestV2,
|
|
14662
15131
|
ImageRequest as ImageRequestSchema,
|
|
15132
|
+
FileUploadResponseV2,
|
|
14663
15133
|
FileUploadResponse as FileUploadResponseSchema,
|
|
14664
15134
|
FileInput as FileInputSchema,
|
|
15135
|
+
FfmpegSliceRequestV2,
|
|
14665
15136
|
FfmpegSliceRequest as FfmpegSliceRequestSchema,
|
|
15137
|
+
FfmpegRequestV2,
|
|
14666
15138
|
FfmpegRequest as FfmpegRequestSchema,
|
|
14667
15139
|
FfmpegProbeResponse as FfmpegProbeResponseSchema,
|
|
14668
15140
|
FfmpegProbeRequest as FfmpegProbeRequestSchema,
|
|
15141
|
+
EstimateResponseV2,
|
|
15142
|
+
EstimateRequestV2,
|
|
15143
|
+
EstimateBatchResponseV2,
|
|
15144
|
+
EstimateBatchResponseItemV2,
|
|
15145
|
+
EstimateBatchRequestV2,
|
|
15146
|
+
EstimateBatchItemV2,
|
|
15147
|
+
ErrorResponseV2,
|
|
14669
15148
|
ErrorResponse as ErrorResponseSchema
|
|
14670
15149
|
};
|