@vargai/gateway 0.1.2 → 0.1.3
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/README.md +1 -1
- package/dist/index.js +24 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ import { createVarg } from "@vargai/gateway";
|
|
|
16
16
|
|
|
17
17
|
const varg = createVarg({
|
|
18
18
|
apiKey: process.env.VARG_API_KEY!,
|
|
19
|
-
baseUrl: "https://varg-
|
|
19
|
+
baseUrl: "https://varg-gateway.fly.dev/v1", // optional
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
const result = await generateVideo({
|
package/dist/index.js
CHANGED
|
@@ -13579,6 +13579,22 @@ var TranscriptionRequest = exports_external.object({
|
|
|
13579
13579
|
language: exports_external.string().optional(),
|
|
13580
13580
|
provider_options: exports_external.record(exports_external.string(), exports_external.unknown()).optional()
|
|
13581
13581
|
});
|
|
13582
|
+
var UsageQuery = exports_external.object({
|
|
13583
|
+
from: exports_external.string().date().optional(),
|
|
13584
|
+
to: exports_external.string().date().optional()
|
|
13585
|
+
});
|
|
13586
|
+
var UsageRecord = exports_external.object({
|
|
13587
|
+
id: exports_external.string(),
|
|
13588
|
+
job_id: exports_external.string(),
|
|
13589
|
+
provider: exports_external.string(),
|
|
13590
|
+
cost_cents: exports_external.number(),
|
|
13591
|
+
billing_type: exports_external.string(),
|
|
13592
|
+
created_at: exports_external.string()
|
|
13593
|
+
});
|
|
13594
|
+
var UsageResponse = exports_external.object({
|
|
13595
|
+
usage: exports_external.array(UsageRecord),
|
|
13596
|
+
total_cents: exports_external.number()
|
|
13597
|
+
});
|
|
13582
13598
|
var JobStatus = exports_external.enum(["queued", "processing", "completed", "failed", "cancelled"]);
|
|
13583
13599
|
var JobResponse = exports_external.object({
|
|
13584
13600
|
job_id: exports_external.string(),
|
|
@@ -13657,7 +13673,7 @@ class VargClient {
|
|
|
13657
13673
|
if (!response.ok) {
|
|
13658
13674
|
const raw = await response.json().catch(() => null);
|
|
13659
13675
|
const errorData = (raw?.error ?? raw) || {};
|
|
13660
|
-
throw new VargGatewayError(errorData?.message ?? `
|
|
13676
|
+
throw new VargGatewayError(errorData?.message ?? `gateway returned ${response.status}`, response.status, errorData?.field, errorData?.provider);
|
|
13661
13677
|
}
|
|
13662
13678
|
const data = await response.json();
|
|
13663
13679
|
return schema.parse(data);
|
|
@@ -14099,6 +14115,9 @@ async function executeJob(client, capability, params) {
|
|
|
14099
14115
|
const job = await submitJob(client, capability, params);
|
|
14100
14116
|
if (job.status === "completed" && job.output?.url) {
|
|
14101
14117
|
const res2 = await fetch(job.output.url);
|
|
14118
|
+
if (!res2.ok) {
|
|
14119
|
+
throw new Error(`[${capability}] failed to download output from ${job.output.url}: ${res2.status}`);
|
|
14120
|
+
}
|
|
14102
14121
|
return {
|
|
14103
14122
|
data: new Uint8Array(await res2.arrayBuffer()),
|
|
14104
14123
|
mediaType: job.output.media_type,
|
|
@@ -14107,13 +14126,16 @@ async function executeJob(client, capability, params) {
|
|
|
14107
14126
|
}
|
|
14108
14127
|
const completed = await client.waitForJob(job.job_id);
|
|
14109
14128
|
if (completed.status === "failed") {
|
|
14110
|
-
throw new Error(
|
|
14129
|
+
throw new Error(`[${capability}] job ${completed.job_id} failed: ${completed.error || "unknown error"}`);
|
|
14111
14130
|
}
|
|
14112
14131
|
const output = completed.output;
|
|
14113
14132
|
if (!output) {
|
|
14114
14133
|
throw new Error(`${capability} completed but no output`);
|
|
14115
14134
|
}
|
|
14116
14135
|
const res = await fetch(output.url);
|
|
14136
|
+
if (!res.ok) {
|
|
14137
|
+
throw new Error(`[${capability}] failed to download output from ${output.url}: ${res.status}`);
|
|
14138
|
+
}
|
|
14117
14139
|
return {
|
|
14118
14140
|
data: new Uint8Array(await res.arrayBuffer()),
|
|
14119
14141
|
mediaType: output.media_type,
|