@vargai/gateway 0.1.4 → 0.1.6

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.d.ts CHANGED
@@ -13,6 +13,22 @@ export interface WaitForJobOptions {
13
13
  pollIntervalMs?: number;
14
14
  maxAttempts?: number;
15
15
  }
16
+ export interface VoiceInfo {
17
+ voice_id: string;
18
+ name: string;
19
+ category: string;
20
+ labels: {
21
+ gender?: string;
22
+ age?: string;
23
+ accent?: string;
24
+ description?: string;
25
+ use_case?: string;
26
+ };
27
+ preview_url?: string;
28
+ }
29
+ export interface VoiceListResponse {
30
+ voices: VoiceInfo[];
31
+ }
16
32
  export declare class VargGatewayError extends Error {
17
33
  statusCode?: number | undefined;
18
34
  field?: string | undefined;
@@ -31,8 +47,11 @@ export declare class VargClient {
31
47
  createSpeech(params: SpeechRequest): Promise<JobResponse>;
32
48
  createMusic(params: MusicRequest): Promise<JobResponse>;
33
49
  uploadFile(file: Blob | Buffer, mediaType: string): Promise<FileUploadResponse>;
50
+ listVoices(): Promise<VoiceListResponse>;
34
51
  getJob(id: string): Promise<JobResponse>;
35
52
  cancelJob(id: string): Promise<void>;
36
53
  waitForJob(id: string, options?: WaitForJobOptions): Promise<JobResponse>;
54
+ private waitForJobSSE;
55
+ private waitForJobPoll;
37
56
  }
38
57
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EAEvB,KAAK,YAAY,EAEjB,KAAK,WAAW,EAEhB,KAAK,YAAY,EAEjB,KAAK,aAAa,EAElB,KAAK,YAAY,EAElB,MAAM,cAAc,CAAC;AAEtB,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE;QACb,GAAG,CAAC,EAAE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AHxB,OAAO,EAAE,MAAM,EACR,UAAU,CAAC,EAAE,MAAM,YAAA,EACnB,KAAK,CAAC,EAAE,MAAM,YAAA,EACd,QAAQ,CAAC,EAAE,MAAM,YAAA;CAK3B;AAED,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,YAAY,CAAmC;gBAE3C,MAAM,EAAE,gBAAgB;IAMpC,OAAO,CAAC,UAAU;YAsBJ,cAAc;IAuBtB,WAAW,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC;IAUvD,WAAW,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC;IAUvD,YAAY,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,WAAW,CAAC;IAUzD,WAAW,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC;IAUvD,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;IA2B/E,UAAU,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAoBxC,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAQxC,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAqBpC,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC;YASjE,aAAa;YA4Eb,cAAc;CAgB7B"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { VargClient, VargGatewayError } from "./client.ts";
2
- export type { VargClientConfig, WaitForJobOptions } from "./client.ts";
2
+ export type { VargClientConfig, WaitForJobOptions, VoiceInfo, VoiceListResponse } from "./client.ts";
3
3
  export { createVarg } from "./provider.ts";
4
4
  export type { VargProvider } from "./provider.ts";
5
5
  export { ErrorResponseSchema, FileInputSchema, FileUploadResponseSchema, ImageRequestSchema, JobResponseSchema, JobStatusSchema, MusicRequestSchema, SpeechRequestSchema, VideoRequestSchema, } from "./schemas.ts";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC3D,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,wBAAwB,EACxB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,cAAc,CAAC;AACtB,YAAY,EACV,aAAa,EACb,SAAS,EACT,kBAAkB,EAClB,YAAY,EACZ,WAAW,EACX,SAAS,EACT,YAAY,EACZ,aAAa,EACb,YAAY,GACb,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC3D,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrG,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,wBAAwB,EACxB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,cAAc,CAAC;AACtB,YAAY,EACV,aAAa,EACb,SAAS,EACT,kBAAkB,EAClB,YAAY,EACZ,WAAW,EACX,SAAS,EACT,YAAY,EACZ,aAAa,EACb,YAAY,GACb,MAAM,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -13738,6 +13738,18 @@ class VargClient {
13738
13738
  });
13739
13739
  return this.handleResponse(response, FileUploadResponse);
13740
13740
  }
13741
+ async listVoices() {
13742
+ const response = await fetch(`${this.baseUrl}/voices`, {
13743
+ method: "GET",
13744
+ headers: this.getHeaders()
13745
+ });
13746
+ if (!response.ok) {
13747
+ const raw = await response.json().catch(() => null);
13748
+ const errorData = (raw?.error ?? raw) || {};
13749
+ throw new VargGatewayError(errorData?.message ?? `gateway returned ${response.status}`, response.status);
13750
+ }
13751
+ return await response.json();
13752
+ }
13741
13753
  async getJob(id) {
13742
13754
  const response = await fetch(`${this.baseUrl}/jobs/${id}`, {
13743
13755
  method: "GET",
@@ -13756,8 +13768,68 @@ class VargClient {
13756
13768
  }
13757
13769
  }
13758
13770
  async waitForJob(id, options) {
13771
+ try {
13772
+ return await this.waitForJobSSE(id, options);
13773
+ } catch {
13774
+ return this.waitForJobPoll(id, options);
13775
+ }
13776
+ }
13777
+ async waitForJobSSE(id, options) {
13778
+ const timeoutMs = (options?.maxAttempts ?? 450) * (options?.pollIntervalMs ?? 2000);
13779
+ const response = await fetch(`${this.baseUrl}/jobs/${id}/stream`, {
13780
+ method: "GET",
13781
+ headers: {
13782
+ Authorization: `Bearer ${this.apiKey}`,
13783
+ Accept: "text/event-stream"
13784
+ }
13785
+ });
13786
+ if (!response.ok || !response.body) {
13787
+ throw new VargGatewayError(`SSE connection failed: ${response.status}`);
13788
+ }
13789
+ return new Promise((resolve, reject) => {
13790
+ const reader = response.body.getReader();
13791
+ const decoder = new TextDecoder;
13792
+ let buffer = "";
13793
+ const timer = setTimeout(() => {
13794
+ reader.cancel();
13795
+ reject(new VargGatewayError(`job ${id} did not complete within timeout`));
13796
+ }, timeoutMs);
13797
+ const read = () => {
13798
+ reader.read().then(({ done, value }) => {
13799
+ if (done) {
13800
+ clearTimeout(timer);
13801
+ this.getJob(id).then(resolve).catch(reject);
13802
+ return;
13803
+ }
13804
+ buffer += decoder.decode(value, { stream: true });
13805
+ const lines = buffer.split(`
13806
+ `);
13807
+ buffer = lines.pop() ?? "";
13808
+ for (const line of lines) {
13809
+ if (!line.startsWith("data: "))
13810
+ continue;
13811
+ try {
13812
+ const data = JSON.parse(line.slice(6));
13813
+ if (data.status === "completed" || data.status === "failed" || data.status === "cancelled") {
13814
+ clearTimeout(timer);
13815
+ reader.cancel();
13816
+ this.getJob(id).then(resolve).catch(reject);
13817
+ return;
13818
+ }
13819
+ } catch {}
13820
+ }
13821
+ read();
13822
+ }).catch((err) => {
13823
+ clearTimeout(timer);
13824
+ reject(err);
13825
+ });
13826
+ };
13827
+ read();
13828
+ });
13829
+ }
13830
+ async waitForJobPoll(id, options) {
13759
13831
  const pollIntervalMs = options?.pollIntervalMs ?? 2000;
13760
- const maxAttempts = options?.maxAttempts ?? 150;
13832
+ const maxAttempts = options?.maxAttempts ?? 450;
13761
13833
  for (let i = 0;i < maxAttempts; i++) {
13762
13834
  const job = await this.getJob(id);
13763
13835
  if (job.status === "completed" || job.status === "failed" || job.status === "cancelled") {
@@ -14164,7 +14236,19 @@ class VargVideoModel {
14164
14236
  if (options.aspectRatio)
14165
14237
  params.aspect_ratio = options.aspectRatio;
14166
14238
  if (options.files && options.files.length > 0) {
14167
- params.files = options.files.filter((f) => f.type === "url").map((f) => ({ url: f.url }));
14239
+ const fileUrls = [];
14240
+ for (const f of options.files) {
14241
+ if (f.type === "url") {
14242
+ fileUrls.push({ url: f.url });
14243
+ } else if (f.type === "file") {
14244
+ const fileData = f;
14245
+ const uploaded = await this.client.uploadFile(new Blob([fileData.data], { type: fileData.mediaType }), fileData.mediaType);
14246
+ fileUrls.push({ url: uploaded.url });
14247
+ }
14248
+ }
14249
+ if (fileUrls.length > 0) {
14250
+ params.files = fileUrls;
14251
+ }
14168
14252
  }
14169
14253
  if (options.providerOptions?.varg) {
14170
14254
  params.provider_options = options.providerOptions.varg;
@@ -14201,7 +14285,19 @@ class VargImageModel {
14201
14285
  if (options.aspectRatio)
14202
14286
  params.aspect_ratio = options.aspectRatio;
14203
14287
  if (options.files && options.files.length > 0) {
14204
- params.files = options.files.filter((f) => f.type === "url").map((f) => ({ url: f.url }));
14288
+ const fileUrls = [];
14289
+ for (const f of options.files) {
14290
+ if (f.type === "url") {
14291
+ fileUrls.push({ url: f.url });
14292
+ } else if (f.type === "file") {
14293
+ const fileData = f;
14294
+ const uploaded = await this.client.uploadFile(new Blob([fileData.data], { type: fileData.mediaType }), fileData.mediaType);
14295
+ fileUrls.push({ url: uploaded.url });
14296
+ }
14297
+ }
14298
+ if (fileUrls.length > 0) {
14299
+ params.files = fileUrls;
14300
+ }
14205
14301
  }
14206
14302
  if (options.providerOptions?.varg) {
14207
14303
  params.provider_options = options.providerOptions.varg;
@@ -14242,8 +14338,7 @@ class VargSpeechModel {
14242
14338
  warnings,
14243
14339
  response: {
14244
14340
  timestamp: new Date,
14245
- modelId: this.modelId,
14246
- headers: undefined
14341
+ modelId: this.modelId
14247
14342
  }
14248
14343
  };
14249
14344
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vargai/gateway",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "typescript client for varg gateway api",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -16,24 +16,13 @@
16
16
  "types": "./src/provider.ts"
17
17
  }
18
18
  },
19
- "files": [
20
- "dist",
21
- "README.md"
22
- ],
19
+ "files": ["dist", "README.md"],
23
20
  "scripts": {
24
21
  "build": "bun build src/index.ts --outdir dist --target bun --format esm && bun run build:types",
25
22
  "build:types": "tsc --emitDeclarationOnly --declaration --outDir dist",
26
23
  "prepublishOnly": "bun run build"
27
24
  },
28
- "keywords": [
29
- "varg",
30
- "ai",
31
- "video",
32
- "image",
33
- "speech",
34
- "music",
35
- "generation"
36
- ],
25
+ "keywords": ["varg", "ai", "video", "image", "speech", "music", "generation"],
37
26
  "author": "varg",
38
27
  "license": "MIT",
39
28
  "publishConfig": {
@@ -46,9 +35,9 @@
46
35
  },
47
36
  "devDependencies": {
48
37
  "@types/bun": "latest",
49
- "@vargai/schemas": "0.1.0",
38
+ "@vargai/schemas": "workspace:*",
50
39
  "typescript": "^5",
51
- "vargai": "^0.4.0-alpha49"
40
+ "vargai": "^0.4.0-alpha61"
52
41
  },
53
42
  "peerDependencies": {
54
43
  "typescript": "^5"