@visgate_ai/client 0.2.22 → 0.3.4

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.d.ts CHANGED
@@ -175,6 +175,124 @@ declare class Models {
175
175
  search(query: string, limit?: number): Promise<ModelsResponse>;
176
176
  }
177
177
 
178
+ /** Deployment management: /deployments endpoints */
179
+
180
+ interface DeploymentCreateOptions {
181
+ modelName?: string;
182
+ hfModelId?: string;
183
+ gpuTier?: string;
184
+ region?: string;
185
+ hfToken?: string;
186
+ runpodKey?: string;
187
+ webhookUrl?: string;
188
+ cacheScope?: "off" | "shared" | "private";
189
+ provider?: string;
190
+ task?: string;
191
+ userS3Url?: string;
192
+ userAwsAccessKeyId?: string;
193
+ userAwsSecretAccessKey?: string;
194
+ userAwsEndpointUrl?: string;
195
+ }
196
+ interface DeploymentInfo {
197
+ deploymentId: string;
198
+ modelId?: string | null;
199
+ status: string;
200
+ endpointUrl?: string | null;
201
+ provider?: string | null;
202
+ createdAt?: string | null;
203
+ gpuAllocated?: string | null;
204
+ modelVramGb?: number | null;
205
+ readyAt?: string | null;
206
+ error?: string | null;
207
+ }
208
+ interface DeploymentListResponse {
209
+ deployments: DeploymentInfo[];
210
+ }
211
+ interface DeploymentGpuInfo {
212
+ id: string;
213
+ displayName: string;
214
+ memoryGb: number;
215
+ secureCloud: boolean;
216
+ communityCloud: boolean;
217
+ bidPricePerHr?: number | null;
218
+ pricePerHr?: number | null;
219
+ }
220
+ interface DeploymentGpuListResponse {
221
+ gpus: DeploymentGpuInfo[];
222
+ }
223
+ interface DeploymentLogEntry {
224
+ timestamp: string;
225
+ level: string;
226
+ message: string;
227
+ }
228
+ interface DeploymentLogsResponse {
229
+ deploymentId: string;
230
+ logs: DeploymentLogEntry[];
231
+ }
232
+ interface DeploymentCostResponse {
233
+ deploymentId: string;
234
+ status: string;
235
+ gpuAllocated?: string | null;
236
+ hoursRunning?: number | null;
237
+ pricePerHourUsd?: number | null;
238
+ estimatedCostUsd?: number | null;
239
+ note?: string | null;
240
+ }
241
+ interface DeploymentRunRequest {
242
+ input: Record<string, unknown>;
243
+ }
244
+ interface StreamStatusEvent {
245
+ deploymentId: string;
246
+ status?: string;
247
+ endpointUrl?: string;
248
+ estimatedRemainingSeconds?: number;
249
+ error?: string;
250
+ }
251
+ declare function deploymentInfoFromResponse(data: Record<string, unknown>): DeploymentInfo;
252
+ declare function deploymentListResponseFromResponse(data: Record<string, unknown>): DeploymentListResponse;
253
+ declare function deploymentGpuInfoFromResponse(data: Record<string, unknown>): DeploymentGpuInfo;
254
+ declare function deploymentGpuListResponseFromResponse(data: Record<string, unknown>): DeploymentGpuListResponse;
255
+ declare function deploymentLogsResponseFromResponse(data: Record<string, unknown>): DeploymentLogsResponse;
256
+ declare function deploymentCostResponseFromResponse(data: Record<string, unknown>): DeploymentCostResponse;
257
+ declare class Deployments {
258
+ private _client;
259
+ constructor(_client: Client);
260
+ create(options: DeploymentCreateOptions): Promise<DeploymentInfo>;
261
+ list(): Promise<DeploymentListResponse>;
262
+ get(deploymentId: string): Promise<DeploymentInfo>;
263
+ delete(deploymentId: string): Promise<void>;
264
+ run(deploymentId: string, input: Record<string, unknown>): Promise<Record<string, unknown>>;
265
+ getLogs(deploymentId: string): Promise<DeploymentLogsResponse>;
266
+ getCost(deploymentId: string): Promise<DeploymentCostResponse>;
267
+ listGpus(): Promise<DeploymentGpuListResponse>;
268
+ /**
269
+ * Streams deployment status events (SSE).
270
+ * Returns an abort function to stop streaming.
271
+ */
272
+ streamStatus(deploymentId: string, onEvent: (event: StreamStatusEvent) => void, onError?: (error: Error) => void): () => void;
273
+ }
274
+
275
+ /**
276
+ * Hugging Face Hub API — list deployable image/video generation models.
277
+ * Calls https://huggingface.co/api/models directly (no Visgate backend).
278
+ */
279
+ interface HfModelInfo {
280
+ id: string;
281
+ modelId: string;
282
+ pipelineTag: string;
283
+ libraryName?: string;
284
+ likes?: number;
285
+ downloads?: number;
286
+ }
287
+ interface HfModelsListOptions {
288
+ task?: "text-to-image" | "image-to-image" | "text-to-video" | "image-to-video";
289
+ limit?: number;
290
+ search?: string;
291
+ }
292
+ declare class HfModels {
293
+ list(options?: HfModelsListOptions): Promise<HfModelInfo[]>;
294
+ }
295
+
178
296
  /** Provider key management and balance resources */
179
297
 
180
298
  interface ProviderKeyInfo {
@@ -419,6 +537,7 @@ interface ClientOptions {
419
537
  falKey?: string | null;
420
538
  replicateKey?: string | null;
421
539
  runwayKey?: string | null;
540
+ runpodKey?: string | null;
422
541
  }
423
542
  interface RequestInitWithBody {
424
543
  body?: string;
@@ -437,6 +556,8 @@ declare class Client {
437
556
  readonly requests: Requests;
438
557
  readonly usage: Usage;
439
558
  readonly providers: Providers;
559
+ readonly deployments: Deployments;
560
+ readonly hfModels: HfModels;
440
561
  readonly billing: Billing;
441
562
  private _generate;
442
563
  constructor(options?: ClientOptions);
@@ -512,6 +633,6 @@ declare class VisgateConnectionError extends VisgateError {
512
633
  * Visgate JavaScript/TypeScript SDK — unified client for the Visgate vision AI gateway.
513
634
  */
514
635
 
515
- declare const VERSION = "0.2.2";
636
+ declare const VERSION = "0.3.4";
516
637
 
517
- export { AsyncClient, type AsyncVideoAccepted, AuthenticationError, Billing, type BillingInfo, type CheckoutOptions, Client, type ClientOptions, type DashboardResponse, type FeaturedSection, Generate, type GenerateResult, type ImageResult, Images, type ImagesGenerateOptions, type ModelInfo, type ModelPricing, Models, type ModelsListOptions, type ModelsResponse, type PricingResponse, type ProviderBalanceItem, type ProviderBalancesResponse, ProviderError, type ProviderKeyInfo, type ProviderKeysResponse, type ProviderValidationResult, Providers, RateLimitError, type RequestStatusResult, Requests, Usage, type UsageSummary, VERSION, VIDEO_MODEL_PRESETS, ValidationError, type VideoResult, Videos, type VideosGenerateOptions, VisgateConnectionError, VisgateError, type VisgateErrorDetails, VisgateTimeoutError, billingInfoFromResponse, featuredSectionFromResponse, generateResultFromResponse, imageResultFromResponse, modelInfoFromResponse, modelPricingFromResponse, modelsResponseFromResponse, pricingResponseFromResponse, providerBalanceItemFromResponse, providerBalancesResponseFromResponse, providerKeyInfoFromResponse, providerKeysResponseFromResponse, providerValidationResultFromResponse, requestStatusFromResponse, usageSummaryFromResponse, videoResultFromResponse };
638
+ export { AsyncClient, type AsyncVideoAccepted, AuthenticationError, Billing, type BillingInfo, type CheckoutOptions, Client, type ClientOptions, type DashboardResponse, type DeploymentCostResponse, type DeploymentCreateOptions, type DeploymentGpuInfo, type DeploymentGpuListResponse, type DeploymentInfo, type DeploymentListResponse, type DeploymentLogEntry, type DeploymentLogsResponse, type DeploymentRunRequest, Deployments, type FeaturedSection, Generate, type GenerateResult, type HfModelInfo, HfModels, type HfModelsListOptions, type ImageResult, Images, type ImagesGenerateOptions, type ModelInfo, type ModelPricing, Models, type ModelsListOptions, type ModelsResponse, type PricingResponse, type ProviderBalanceItem, type ProviderBalancesResponse, ProviderError, type ProviderKeyInfo, type ProviderKeysResponse, type ProviderValidationResult, Providers, RateLimitError, type RequestStatusResult, Requests, type StreamStatusEvent, Usage, type UsageSummary, VERSION, VIDEO_MODEL_PRESETS, ValidationError, type VideoResult, Videos, type VideosGenerateOptions, VisgateConnectionError, VisgateError, type VisgateErrorDetails, VisgateTimeoutError, billingInfoFromResponse, deploymentCostResponseFromResponse, deploymentGpuInfoFromResponse, deploymentGpuListResponseFromResponse, deploymentInfoFromResponse, deploymentListResponseFromResponse, deploymentLogsResponseFromResponse, featuredSectionFromResponse, generateResultFromResponse, imageResultFromResponse, modelInfoFromResponse, modelPricingFromResponse, modelsResponseFromResponse, pricingResponseFromResponse, providerBalanceItemFromResponse, providerBalancesResponseFromResponse, providerKeyInfoFromResponse, providerKeysResponseFromResponse, providerValidationResultFromResponse, requestStatusFromResponse, usageSummaryFromResponse, videoResultFromResponse };
package/dist/index.js CHANGED
@@ -324,6 +324,219 @@ var Models = class {
324
324
  }
325
325
  };
326
326
 
327
+ // src/resources/deployments.ts
328
+ function deploymentInfoFromResponse(data) {
329
+ return {
330
+ deploymentId: data.deployment_id ?? data.deploymentId ?? "",
331
+ modelId: data.model_id ?? data.modelId,
332
+ status: data.status ?? "unknown",
333
+ endpointUrl: data.endpoint_url ?? data.endpointUrl,
334
+ provider: data.provider ?? "runpod",
335
+ createdAt: data.created_at ?? data.createdAt,
336
+ gpuAllocated: data.gpu_allocated ?? data.gpuAllocated,
337
+ modelVramGb: data.model_vram_gb ?? data.modelVramGb,
338
+ readyAt: data.ready_at ?? data.readyAt,
339
+ error: data.error ?? null
340
+ };
341
+ }
342
+ function deploymentListResponseFromResponse(data) {
343
+ const deployments = data.deployments ?? [];
344
+ return { deployments: deployments.map(deploymentInfoFromResponse) };
345
+ }
346
+ function deploymentGpuInfoFromResponse(data) {
347
+ return {
348
+ id: data.id ?? "",
349
+ displayName: data.display_name ?? data.displayName ?? "",
350
+ memoryGb: data.memory_gb ?? data.memoryGb ?? 0,
351
+ secureCloud: Boolean(data.secure_cloud ?? data.secureCloud),
352
+ communityCloud: Boolean(data.community_cloud ?? data.communityCloud),
353
+ bidPricePerHr: data.bid_price_per_hr ?? data.bidPricePerHr,
354
+ pricePerHr: data.price_per_hr ?? data.pricePerHr
355
+ };
356
+ }
357
+ function deploymentGpuListResponseFromResponse(data) {
358
+ const gpus = data.gpus ?? [];
359
+ return { gpus: gpus.map(deploymentGpuInfoFromResponse) };
360
+ }
361
+ function deploymentLogsResponseFromResponse(data) {
362
+ const rawLogs = data.logs ?? [];
363
+ return {
364
+ deploymentId: data.deployment_id ?? data.deploymentId ?? "",
365
+ logs: rawLogs.map((entry) => ({
366
+ timestamp: entry.timestamp ?? "",
367
+ level: entry.level ?? "INFO",
368
+ message: entry.message ?? ""
369
+ }))
370
+ };
371
+ }
372
+ function deploymentCostResponseFromResponse(data) {
373
+ return {
374
+ deploymentId: data.deployment_id ?? data.deploymentId ?? "",
375
+ status: data.status ?? "unknown",
376
+ gpuAllocated: data.gpu_allocated ?? data.gpuAllocated,
377
+ hoursRunning: data.hours_running ?? data.hoursRunning,
378
+ pricePerHourUsd: data.price_per_hour_usd ?? data.pricePerHourUsd,
379
+ estimatedCostUsd: data.estimated_cost_usd ?? data.estimatedCostUsd,
380
+ note: data.note ?? null
381
+ };
382
+ }
383
+ var Deployments = class {
384
+ constructor(_client) {
385
+ this._client = _client;
386
+ }
387
+ async create(options) {
388
+ const data = await this._client._request("POST", "/deployments", {
389
+ body: JSON.stringify({
390
+ model_name: options.modelName,
391
+ hf_model_id: options.hfModelId,
392
+ gpu_tier: options.gpuTier,
393
+ region: options.region,
394
+ hf_token: options.hfToken,
395
+ runpod_key: options.runpodKey,
396
+ webhook_url: options.webhookUrl,
397
+ cache_scope: options.cacheScope,
398
+ provider: options.provider,
399
+ task: options.task,
400
+ user_s3_url: options.userS3Url,
401
+ user_aws_access_key_id: options.userAwsAccessKeyId,
402
+ user_aws_secret_access_key: options.userAwsSecretAccessKey,
403
+ user_aws_endpoint_url: options.userAwsEndpointUrl
404
+ })
405
+ });
406
+ return deploymentInfoFromResponse(data);
407
+ }
408
+ async list() {
409
+ const data = await this._client._request("GET", "/deployments");
410
+ return deploymentListResponseFromResponse(data);
411
+ }
412
+ async get(deploymentId) {
413
+ const data = await this._client._request(
414
+ "GET",
415
+ `/deployments/${encodeURIComponent(deploymentId)}`
416
+ );
417
+ return deploymentInfoFromResponse(data);
418
+ }
419
+ async delete(deploymentId) {
420
+ await this._client._request("DELETE", `/deployments/${encodeURIComponent(deploymentId)}`);
421
+ }
422
+ async run(deploymentId, input) {
423
+ const data = await this._client._request("POST", `/deployments/${encodeURIComponent(deploymentId)}/run`, {
424
+ body: JSON.stringify({ input })
425
+ });
426
+ return data;
427
+ }
428
+ async getLogs(deploymentId) {
429
+ const data = await this._client._request(
430
+ "GET",
431
+ `/deployments/${encodeURIComponent(deploymentId)}/logs`
432
+ );
433
+ return deploymentLogsResponseFromResponse(data);
434
+ }
435
+ async getCost(deploymentId) {
436
+ const data = await this._client._request(
437
+ "GET",
438
+ `/deployments/${encodeURIComponent(deploymentId)}/cost`
439
+ );
440
+ return deploymentCostResponseFromResponse(data);
441
+ }
442
+ async listGpus() {
443
+ const data = await this._client._request("GET", "/deployments/gpus");
444
+ return deploymentGpuListResponseFromResponse(data);
445
+ }
446
+ /**
447
+ * Streams deployment status events (SSE).
448
+ * Returns an abort function to stop streaming.
449
+ */
450
+ streamStatus(deploymentId, onEvent, onError) {
451
+ const controller = new AbortController();
452
+ const base = this._client.baseUrl.replace(/\/$/, "");
453
+ const url = `${base}/deployments/${encodeURIComponent(deploymentId)}/stream`;
454
+ const headers = {};
455
+ if (this._client.apiKey) headers.Authorization = `Bearer ${this._client.apiKey}`;
456
+ void (async () => {
457
+ try {
458
+ const response = await fetch(url, {
459
+ method: "GET",
460
+ headers,
461
+ signal: controller.signal
462
+ });
463
+ if (!response.ok || !response.body) {
464
+ throw new Error(`SSE stream failed with status ${response.status}`);
465
+ }
466
+ const decoder = new TextDecoder();
467
+ const reader = response.body.getReader();
468
+ let buffer = "";
469
+ while (true) {
470
+ const { value, done } = await reader.read();
471
+ if (done) break;
472
+ buffer += decoder.decode(value, { stream: true });
473
+ const events = buffer.split("\n\n");
474
+ buffer = events.pop() ?? "";
475
+ for (const rawEvent of events) {
476
+ const dataLine = rawEvent.split("\n").find((line) => line.startsWith("data:"));
477
+ if (!dataLine) continue;
478
+ const payload = dataLine.slice(5).trim();
479
+ if (!payload) continue;
480
+ try {
481
+ const parsed = JSON.parse(payload);
482
+ onEvent({
483
+ deploymentId: parsed.deployment_id ?? parsed.deploymentId ?? deploymentId,
484
+ status: parsed.status,
485
+ endpointUrl: parsed.endpoint_url ?? parsed.endpointUrl,
486
+ estimatedRemainingSeconds: parsed.estimated_remaining_seconds,
487
+ error: parsed.error
488
+ });
489
+ } catch {
490
+ }
491
+ }
492
+ }
493
+ } catch (err) {
494
+ if (!controller.signal.aborted) {
495
+ const error = err instanceof Error ? err : new Error(String(err));
496
+ onError?.(error);
497
+ }
498
+ }
499
+ })();
500
+ return () => controller.abort();
501
+ }
502
+ };
503
+
504
+ // src/resources/hf-models.ts
505
+ var HF_API_BASE = "https://huggingface.co/api/models";
506
+ function normalizeModel(raw) {
507
+ const id = raw.id ?? raw.modelId ?? "";
508
+ return {
509
+ id,
510
+ modelId: raw.modelId ?? id,
511
+ pipelineTag: raw.pipeline_tag ?? "",
512
+ libraryName: raw.library_name,
513
+ likes: raw.likes,
514
+ downloads: raw.downloads
515
+ };
516
+ }
517
+ var HfModels = class {
518
+ async list(options = {}) {
519
+ const task = options.task ?? "text-to-image";
520
+ const limit = Math.min(Math.max(options.limit ?? 50, 1), 100);
521
+ const params = new URLSearchParams();
522
+ params.set("pipeline_tag", task);
523
+ params.set("limit", String(limit));
524
+ if (options.search && options.search.trim()) {
525
+ params.set("search", options.search.trim());
526
+ }
527
+ const url = `${HF_API_BASE}?${params.toString()}`;
528
+ const response = await fetch(url);
529
+ if (!response.ok) {
530
+ throw new Error(`Hugging Face API error: ${response.status} ${response.statusText}`);
531
+ }
532
+ const data = await response.json();
533
+ if (!Array.isArray(data)) {
534
+ return [];
535
+ }
536
+ return data.map((item) => normalizeModel(item));
537
+ }
538
+ };
539
+
327
540
  // src/resources/providers.ts
328
541
  function providerKeyInfoFromResponse(data) {
329
542
  return {
@@ -591,7 +804,7 @@ var DEFAULT_BASE_URL = "https://visgateai.com/api/v1";
591
804
  var DEFAULT_TIMEOUT = 12e4;
592
805
  var DEFAULT_MAX_RETRIES = 2;
593
806
  var RETRYABLE_STATUS_CODES = /* @__PURE__ */ new Set([429, 500, 502, 503, 504]);
594
- var SDK_VERSION = "0.2.2";
807
+ var SDK_VERSION = "0.3.3";
595
808
  function getVersion() {
596
809
  try {
597
810
  if (typeof __VERSION__ !== "undefined") return __VERSION__;
@@ -608,6 +821,7 @@ function buildHeaders(apiKey, options) {
608
821
  if (options.falKey) headers["X-Fal-Key"] = options.falKey;
609
822
  if (options.replicateKey) headers["X-Replicate-Key"] = options.replicateKey;
610
823
  if (options.runwayKey) headers["X-Runway-Key"] = options.runwayKey;
824
+ if (options.runpodKey) headers["X-Runpod-Key"] = options.runpodKey;
611
825
  return headers;
612
826
  }
613
827
  function backoff(attempt) {
@@ -672,7 +886,8 @@ var Client = class {
672
886
  this.headers = buildHeaders(this.apiKey, options.proxyUrl ? {} : {
673
887
  falKey: options.falKey,
674
888
  replicateKey: options.replicateKey,
675
- runwayKey: options.runwayKey
889
+ runwayKey: options.runwayKey,
890
+ runpodKey: options.runpodKey
676
891
  });
677
892
  this.images = new Images(this);
678
893
  this.models = new Models(this);
@@ -680,6 +895,8 @@ var Client = class {
680
895
  this.requests = new Requests(this);
681
896
  this.usage = new Usage(this);
682
897
  this.providers = new Providers(this);
898
+ this.deployments = new Deployments(this);
899
+ this.hfModels = new HfModels();
683
900
  this.billing = new Billing(this);
684
901
  this._generate = new Generate(this);
685
902
  }
@@ -769,8 +986,8 @@ var AsyncClient = class extends Client {
769
986
  };
770
987
 
771
988
  // src/index.ts
772
- var VERSION = "0.2.2";
989
+ var VERSION = "0.3.4";
773
990
 
774
- export { AsyncClient, AuthenticationError, Billing, Client, Generate, Images, Models, ProviderError, Providers, RateLimitError, Requests, Usage, VERSION, VIDEO_MODEL_PRESETS, ValidationError, Videos, VisgateConnectionError, VisgateError, VisgateTimeoutError, billingInfoFromResponse, featuredSectionFromResponse, generateResultFromResponse, imageResultFromResponse, modelInfoFromResponse, modelPricingFromResponse, modelsResponseFromResponse, pricingResponseFromResponse, providerBalanceItemFromResponse, providerBalancesResponseFromResponse, providerKeyInfoFromResponse, providerKeysResponseFromResponse, providerValidationResultFromResponse, requestStatusFromResponse, usageSummaryFromResponse, videoResultFromResponse };
991
+ export { AsyncClient, AuthenticationError, Billing, Client, Deployments, Generate, HfModels, Images, Models, ProviderError, Providers, RateLimitError, Requests, Usage, VERSION, VIDEO_MODEL_PRESETS, ValidationError, Videos, VisgateConnectionError, VisgateError, VisgateTimeoutError, billingInfoFromResponse, deploymentCostResponseFromResponse, deploymentGpuInfoFromResponse, deploymentGpuListResponseFromResponse, deploymentInfoFromResponse, deploymentListResponseFromResponse, deploymentLogsResponseFromResponse, featuredSectionFromResponse, generateResultFromResponse, imageResultFromResponse, modelInfoFromResponse, modelPricingFromResponse, modelsResponseFromResponse, pricingResponseFromResponse, providerBalanceItemFromResponse, providerBalancesResponseFromResponse, providerKeyInfoFromResponse, providerKeysResponseFromResponse, providerValidationResultFromResponse, requestStatusFromResponse, usageSummaryFromResponse, videoResultFromResponse };
775
992
  //# sourceMappingURL=index.js.map
776
993
  //# sourceMappingURL=index.js.map