diffio 0.4.63 → 1.0.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/README.md +208 -296
- package/dist/Client.d.ts +85 -148
- package/dist/Client.js +73 -798
- package/dist/api/resources/account.d.ts +38 -0
- package/dist/api/resources/account.js +96 -0
- package/dist/api/resources/editing.d.ts +54 -0
- package/dist/api/resources/editing.js +168 -0
- package/dist/api/resources/generations.d.ts +52 -0
- package/dist/api/resources/generations.js +145 -0
- package/dist/api/resources/index.d.ts +5 -7
- package/dist/api/resources/index.js +18 -15
- package/dist/api/resources/models.d.ts +9 -0
- package/dist/api/resources/models.js +23 -0
- package/dist/api/resources/projects.d.ts +51 -0
- package/dist/api/resources/projects.js +128 -0
- package/dist/api/types.d.ts +423 -222
- package/dist/api/types.js +2 -0
- package/dist/core/edgeUpload.d.ts +39 -39
- package/dist/core/edgeUpload.js +170 -125
- package/dist/core/files.d.ts +15 -0
- package/dist/core/files.js +121 -0
- package/dist/core/node.d.ts +7 -0
- package/dist/core/node.js +17 -0
- package/dist/core/pagination.d.ts +33 -0
- package/dist/core/pagination.js +64 -0
- package/dist/core/poll.d.ts +23 -0
- package/dist/core/poll.js +30 -0
- package/dist/core/retry.d.ts +8 -7
- package/dist/core/retry.js +39 -25
- package/dist/core/transport.d.ts +75 -0
- package/dist/core/transport.js +220 -0
- package/dist/core/url.d.ts +10 -0
- package/dist/core/url.js +38 -0
- package/dist/core/webhookSignature.d.ts +20 -0
- package/dist/core/webhookSignature.js +147 -0
- package/dist/errors/index.d.ts +60 -18
- package/dist/errors/index.js +61 -13
- package/dist/index.d.ts +8 -1
- package/dist/index.js +9 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -7
- package/dist/BaseClient.d.ts +0 -26
- package/dist/BaseClient.js +0 -17
- package/dist/api/resources/account/client/Client.d.ts +0 -15
- package/dist/api/resources/account/client/Client.js +0 -15
- package/dist/api/resources/apiKeys/client/Client.d.ts +0 -27
- package/dist/api/resources/apiKeys/client/Client.js +0 -21
- package/dist/api/resources/audioIsolation/client/Client.d.ts +0 -43
- package/dist/api/resources/audioIsolation/client/Client.js +0 -33
- package/dist/api/resources/generations/client/Client.d.ts +0 -48
- package/dist/api/resources/generations/client/Client.js +0 -36
- package/dist/api/resources/projects/client/Client.d.ts +0 -21
- package/dist/api/resources/projects/client/Client.js +0 -19
- package/dist/api/resources/usage/client/Client.d.ts +0 -11
- package/dist/api/resources/usage/client/Client.js +0 -12
- package/dist/api/resources/webhooks/client/Client.d.ts +0 -29
- package/dist/api/resources/webhooks/client/Client.js +0 -76
- package/dist/api/serialization.d.ts +0 -21
- package/dist/api/serialization.js +0 -274
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type { DiffioClient } from "../../../../Client";
|
|
2
|
-
import type { AcceptedModelKey, CreateGenerationResponse, GenerationDownloadResponse, GenerationProgressResponse } from "../../../types";
|
|
3
|
-
export interface GenerationCreateOptions {
|
|
4
|
-
apiProjectId: string;
|
|
5
|
-
model?: AcceptedModelKey;
|
|
6
|
-
sampling?: Record<string, unknown>;
|
|
7
|
-
params?: Record<string, unknown>;
|
|
8
|
-
idempotencyKey?: string;
|
|
9
|
-
requestOptions?: DiffioClient.RequestOptions;
|
|
10
|
-
}
|
|
11
|
-
export interface GenerationProgressOptions {
|
|
12
|
-
generationId: string;
|
|
13
|
-
apiProjectId?: string;
|
|
14
|
-
requestOptions?: DiffioClient.RequestOptions;
|
|
15
|
-
}
|
|
16
|
-
export interface GenerationDownloadOptions {
|
|
17
|
-
generationId: string;
|
|
18
|
-
apiProjectId: string;
|
|
19
|
-
downloadType?: string;
|
|
20
|
-
requestOptions?: DiffioClient.RequestOptions;
|
|
21
|
-
}
|
|
22
|
-
export interface GenerationWaitOptions {
|
|
23
|
-
generationId: string;
|
|
24
|
-
apiProjectId?: string;
|
|
25
|
-
pollInterval?: number;
|
|
26
|
-
timeout?: number;
|
|
27
|
-
timeoutInSeconds?: number;
|
|
28
|
-
onProgress?: (progress: GenerationProgressResponse) => void | Promise<void>;
|
|
29
|
-
showProgress?: boolean;
|
|
30
|
-
requestOptions?: DiffioClient.RequestOptions;
|
|
31
|
-
}
|
|
32
|
-
export interface GenerationCreateAndWaitOptions extends GenerationCreateOptions {
|
|
33
|
-
pollInterval?: number;
|
|
34
|
-
timeout?: number;
|
|
35
|
-
timeoutInSeconds?: number;
|
|
36
|
-
onProgress?: (progress: GenerationProgressResponse) => void | Promise<void>;
|
|
37
|
-
showProgress?: boolean;
|
|
38
|
-
progressRequestOptions?: DiffioClient.RequestOptions;
|
|
39
|
-
}
|
|
40
|
-
export declare class GenerationsClient {
|
|
41
|
-
private _parent;
|
|
42
|
-
constructor(parent: DiffioClient);
|
|
43
|
-
create(options: GenerationCreateOptions): Promise<CreateGenerationResponse>;
|
|
44
|
-
getProgress(options: GenerationProgressOptions): Promise<GenerationProgressResponse>;
|
|
45
|
-
getDownload(options: GenerationDownloadOptions): Promise<GenerationDownloadResponse>;
|
|
46
|
-
waitForComplete(options: GenerationWaitOptions): Promise<GenerationProgressResponse>;
|
|
47
|
-
createAndWait(options: GenerationCreateAndWaitOptions): Promise<[CreateGenerationResponse, GenerationProgressResponse]>;
|
|
48
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GenerationsClient = void 0;
|
|
4
|
-
class GenerationsClient {
|
|
5
|
-
constructor(parent) {
|
|
6
|
-
this._parent = parent;
|
|
7
|
-
}
|
|
8
|
-
async create(options) {
|
|
9
|
-
return this._parent.createGeneration(options);
|
|
10
|
-
}
|
|
11
|
-
async getProgress(options) {
|
|
12
|
-
return this._parent.getGenerationProgress(options);
|
|
13
|
-
}
|
|
14
|
-
async getDownload(options) {
|
|
15
|
-
return this._parent.getGenerationDownload(options);
|
|
16
|
-
}
|
|
17
|
-
async waitForComplete(options) {
|
|
18
|
-
return this._parent.waitForGeneration(options);
|
|
19
|
-
}
|
|
20
|
-
async createAndWait(options) {
|
|
21
|
-
const { progressRequestOptions, ...createOptions } = options;
|
|
22
|
-
const generation = await this.create(createOptions);
|
|
23
|
-
const progress = await this.waitForComplete({
|
|
24
|
-
generationId: generation.generationId,
|
|
25
|
-
apiProjectId: generation.apiProjectId,
|
|
26
|
-
pollInterval: options.pollInterval,
|
|
27
|
-
timeout: options.timeout,
|
|
28
|
-
timeoutInSeconds: options.timeoutInSeconds,
|
|
29
|
-
onProgress: options.onProgress,
|
|
30
|
-
showProgress: options.showProgress,
|
|
31
|
-
requestOptions: progressRequestOptions ?? options.requestOptions
|
|
32
|
-
});
|
|
33
|
-
return [generation, progress];
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
exports.GenerationsClient = GenerationsClient;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { DiffioClient } from "../../../../Client";
|
|
2
|
-
import type { CompleteProjectUploadResponse, ListProjectGenerationsResponse, ListProjectsResponse } from "../../../types";
|
|
3
|
-
export interface ProjectsListOptions {
|
|
4
|
-
requestOptions?: DiffioClient.RequestOptions;
|
|
5
|
-
}
|
|
6
|
-
export interface ProjectsListGenerationsOptions {
|
|
7
|
-
apiProjectId: string;
|
|
8
|
-
requestOptions?: DiffioClient.RequestOptions;
|
|
9
|
-
}
|
|
10
|
-
export interface ProjectsCompleteUploadOptions {
|
|
11
|
-
apiProjectId: string;
|
|
12
|
-
requestOptions?: DiffioClient.RequestOptions;
|
|
13
|
-
}
|
|
14
|
-
export declare class ProjectsClient {
|
|
15
|
-
private _parent;
|
|
16
|
-
constructor(parent: DiffioClient);
|
|
17
|
-
list(options?: ProjectsListOptions): Promise<ListProjectsResponse>;
|
|
18
|
-
/** Confirms a finished edge upload and starts preprocessing; createProject already does this. */
|
|
19
|
-
completeUpload(options: ProjectsCompleteUploadOptions): Promise<CompleteProjectUploadResponse>;
|
|
20
|
-
listGenerations(options: ProjectsListGenerationsOptions): Promise<ListProjectGenerationsResponse>;
|
|
21
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ProjectsClient = void 0;
|
|
4
|
-
class ProjectsClient {
|
|
5
|
-
constructor(parent) {
|
|
6
|
-
this._parent = parent;
|
|
7
|
-
}
|
|
8
|
-
async list(options = {}) {
|
|
9
|
-
return this._parent.listProjects(options);
|
|
10
|
-
}
|
|
11
|
-
/** Confirms a finished edge upload and starts preprocessing; createProject already does this. */
|
|
12
|
-
async completeUpload(options) {
|
|
13
|
-
return this._parent.completeProjectUpload(options);
|
|
14
|
-
}
|
|
15
|
-
async listGenerations(options) {
|
|
16
|
-
return this._parent.listProjectGenerations(options);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.ProjectsClient = ProjectsClient;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { DiffioClient } from "../../../../Client";
|
|
2
|
-
import type { UsageSummaryResponse } from "../../../types";
|
|
3
|
-
export interface UsageSummaryOptions {
|
|
4
|
-
apiKeyId?: string;
|
|
5
|
-
requestOptions?: DiffioClient.RequestOptions;
|
|
6
|
-
}
|
|
7
|
-
export declare class UsageClient {
|
|
8
|
-
private _parent;
|
|
9
|
-
constructor(parent: DiffioClient);
|
|
10
|
-
summary(options?: UsageSummaryOptions): Promise<UsageSummaryResponse>;
|
|
11
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UsageClient = void 0;
|
|
4
|
-
class UsageClient {
|
|
5
|
-
constructor(parent) {
|
|
6
|
-
this._parent = parent;
|
|
7
|
-
}
|
|
8
|
-
async summary(options = {}) {
|
|
9
|
-
return this._parent.getUsageSummary(options);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
exports.UsageClient = UsageClient;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { DiffioClient } from "../../../../Client";
|
|
2
|
-
import type { GenerationWebhookEvent, WebhookConfigureResponse, WebhookTestEventResponse } from "../../../types";
|
|
3
|
-
export interface WebhookTestEventOptions {
|
|
4
|
-
eventType: string;
|
|
5
|
-
mode: string;
|
|
6
|
-
apiKeyId?: string;
|
|
7
|
-
samplePayload?: Record<string, unknown>;
|
|
8
|
-
requestOptions?: DiffioClient.RequestOptions;
|
|
9
|
-
}
|
|
10
|
-
export interface WebhookConfigureOptions {
|
|
11
|
-
mode: string;
|
|
12
|
-
url: string;
|
|
13
|
-
eventTypes: string[];
|
|
14
|
-
apiKeyId?: string;
|
|
15
|
-
requestOptions?: DiffioClient.RequestOptions;
|
|
16
|
-
}
|
|
17
|
-
export type WebhookHeaders = Record<string, string | string[] | undefined> | Headers;
|
|
18
|
-
export interface WebhookVerifyOptions {
|
|
19
|
-
payload: string | Uint8Array;
|
|
20
|
-
headers: WebhookHeaders;
|
|
21
|
-
secret: string;
|
|
22
|
-
}
|
|
23
|
-
export declare class WebhooksClient {
|
|
24
|
-
private _parent;
|
|
25
|
-
constructor(parent: DiffioClient);
|
|
26
|
-
sendTestEvent(options: WebhookTestEventOptions): Promise<WebhookTestEventResponse>;
|
|
27
|
-
configure(options: WebhookConfigureOptions): Promise<WebhookConfigureResponse>;
|
|
28
|
-
verifySignature(options: WebhookVerifyOptions): GenerationWebhookEvent;
|
|
29
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WebhooksClient = void 0;
|
|
4
|
-
const errors_1 = require("../../../../errors");
|
|
5
|
-
const serialization_1 = require("../../../serialization");
|
|
6
|
-
const svix_1 = require("svix");
|
|
7
|
-
class WebhooksClient {
|
|
8
|
-
constructor(parent) {
|
|
9
|
-
this._parent = parent;
|
|
10
|
-
}
|
|
11
|
-
async sendTestEvent(options) {
|
|
12
|
-
return this._parent.sendWebhookTestEvent(options);
|
|
13
|
-
}
|
|
14
|
-
async configure(options) {
|
|
15
|
-
return this._parent.configureWebhook(options);
|
|
16
|
-
}
|
|
17
|
-
verifySignature(options) {
|
|
18
|
-
const { payload, headers, secret } = options;
|
|
19
|
-
if (!secret) {
|
|
20
|
-
throw new errors_1.DiffioApiError("secret is required");
|
|
21
|
-
}
|
|
22
|
-
const normalizedHeaders = normalizeSvixHeaders(headers);
|
|
23
|
-
const body = normalizePayload(payload);
|
|
24
|
-
const webhook = new svix_1.Webhook(secret);
|
|
25
|
-
try {
|
|
26
|
-
const event = webhook.verify(body, normalizedHeaders);
|
|
27
|
-
if (!event || typeof event !== "object") {
|
|
28
|
-
throw new errors_1.DiffioApiError("Webhook payload must be an object");
|
|
29
|
-
}
|
|
30
|
-
return (0, serialization_1.parseGenerationWebhookEvent)(event);
|
|
31
|
-
}
|
|
32
|
-
catch (error) {
|
|
33
|
-
if (error instanceof errors_1.DiffioApiError) {
|
|
34
|
-
throw error;
|
|
35
|
-
}
|
|
36
|
-
const message = error instanceof Error ? error.message : "Webhook signature verification failed";
|
|
37
|
-
throw new errors_1.DiffioApiError(message);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
exports.WebhooksClient = WebhooksClient;
|
|
42
|
-
function normalizePayload(payload) {
|
|
43
|
-
if (typeof payload === "string") {
|
|
44
|
-
return payload;
|
|
45
|
-
}
|
|
46
|
-
if (typeof Buffer !== "undefined") {
|
|
47
|
-
return Buffer.from(payload).toString("utf8");
|
|
48
|
-
}
|
|
49
|
-
return new TextDecoder().decode(payload);
|
|
50
|
-
}
|
|
51
|
-
function normalizeSvixHeaders(headers) {
|
|
52
|
-
const normalized = {};
|
|
53
|
-
if (typeof Headers !== "undefined" && headers instanceof Headers) {
|
|
54
|
-
for (const [key, value] of headers.entries()) {
|
|
55
|
-
normalized[key.toLowerCase()] = value;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
for (const [key, value] of Object.entries(headers)) {
|
|
60
|
-
if (value == null) {
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
normalized[key.toLowerCase()] = Array.isArray(value) ? value.join(",") : String(value);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
const required = ["svix-id", "svix-timestamp", "svix-signature"];
|
|
67
|
-
const missing = required.filter((header) => !normalized[header]);
|
|
68
|
-
if (missing.length > 0) {
|
|
69
|
-
throw new errors_1.DiffioApiError(`Missing webhook headers: ${missing.join(", ")}`);
|
|
70
|
-
}
|
|
71
|
-
return {
|
|
72
|
-
"svix-id": normalized["svix-id"],
|
|
73
|
-
"svix-timestamp": normalized["svix-timestamp"],
|
|
74
|
-
"svix-signature": normalized["svix-signature"]
|
|
75
|
-
};
|
|
76
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { EdgeUploadSession } from "../core/edgeUpload";
|
|
2
|
-
import type { AccountSettingsResponse, ApiKeyResponse, ApiKeysListResponse, AudioIsolationResult, CompleteProjectUploadResponse, CreateGenerationResponse, CreateProjectResponse, GenerationWebhookEvent, GenerationDownloadResponse, GenerationProgressResponse, GenerationProgressStage, ListProjectGenerationsResponse, ListProjectsResponse, ProjectGenerationSummary, ProjectSummary, UsageSummaryResponse, WebhookConfigureResponse, WebhookTestEventResponse } from "./types";
|
|
3
|
-
/** Builds the public createProject result; it omits the upload token, which can still overwrite the upload. */
|
|
4
|
-
export declare function createProjectUploadResult(data: any, session: EdgeUploadSession, uploadCompletion: CompleteProjectUploadResponse): CreateProjectResponse;
|
|
5
|
-
export declare function parseCompleteProjectUploadResponse(data: any): CompleteProjectUploadResponse;
|
|
6
|
-
export declare function parseProjectSummary(data: any): ProjectSummary;
|
|
7
|
-
export declare function parseListProjectsResponse(data: any): ListProjectsResponse;
|
|
8
|
-
export declare function parseCreateGenerationResponse(data: any): CreateGenerationResponse;
|
|
9
|
-
export declare function parseProjectGenerationSummary(data: any): ProjectGenerationSummary;
|
|
10
|
-
export declare function parseListProjectGenerationsResponse(data: any): ListProjectGenerationsResponse;
|
|
11
|
-
export declare function parseGenerationProgressStage(data: any): GenerationProgressStage;
|
|
12
|
-
export declare function parseGenerationProgressResponse(data: any): GenerationProgressResponse;
|
|
13
|
-
export declare function parseGenerationDownloadResponse(data: any): GenerationDownloadResponse;
|
|
14
|
-
export declare function parseWebhookTestEventResponse(data: any): WebhookTestEventResponse;
|
|
15
|
-
export declare function parseAccountSettingsResponse(data: any): AccountSettingsResponse;
|
|
16
|
-
export declare function parseApiKeyResponse(data: any): ApiKeyResponse;
|
|
17
|
-
export declare function parseApiKeysListResponse(data: any): ApiKeysListResponse;
|
|
18
|
-
export declare function parseUsageSummaryResponse(data: any): UsageSummaryResponse;
|
|
19
|
-
export declare function parseWebhookConfigureResponse(data: any): WebhookConfigureResponse;
|
|
20
|
-
export declare function parseGenerationWebhookEvent(data: any): GenerationWebhookEvent;
|
|
21
|
-
export declare function createAudioIsolationResult(project: CreateProjectResponse, generation: CreateGenerationResponse): AudioIsolationResult;
|
|
@@ -1,274 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createProjectUploadResult = createProjectUploadResult;
|
|
4
|
-
exports.parseCompleteProjectUploadResponse = parseCompleteProjectUploadResponse;
|
|
5
|
-
exports.parseProjectSummary = parseProjectSummary;
|
|
6
|
-
exports.parseListProjectsResponse = parseListProjectsResponse;
|
|
7
|
-
exports.parseCreateGenerationResponse = parseCreateGenerationResponse;
|
|
8
|
-
exports.parseProjectGenerationSummary = parseProjectGenerationSummary;
|
|
9
|
-
exports.parseListProjectGenerationsResponse = parseListProjectGenerationsResponse;
|
|
10
|
-
exports.parseGenerationProgressStage = parseGenerationProgressStage;
|
|
11
|
-
exports.parseGenerationProgressResponse = parseGenerationProgressResponse;
|
|
12
|
-
exports.parseGenerationDownloadResponse = parseGenerationDownloadResponse;
|
|
13
|
-
exports.parseWebhookTestEventResponse = parseWebhookTestEventResponse;
|
|
14
|
-
exports.parseAccountSettingsResponse = parseAccountSettingsResponse;
|
|
15
|
-
exports.parseApiKeyResponse = parseApiKeyResponse;
|
|
16
|
-
exports.parseApiKeysListResponse = parseApiKeysListResponse;
|
|
17
|
-
exports.parseUsageSummaryResponse = parseUsageSummaryResponse;
|
|
18
|
-
exports.parseWebhookConfigureResponse = parseWebhookConfigureResponse;
|
|
19
|
-
exports.parseGenerationWebhookEvent = parseGenerationWebhookEvent;
|
|
20
|
-
exports.createAudioIsolationResult = createAudioIsolationResult;
|
|
21
|
-
/** Builds the public createProject result; it omits the upload token, which can still overwrite the upload. */
|
|
22
|
-
function createProjectUploadResult(data, session, uploadCompletion) {
|
|
23
|
-
const upload = {
|
|
24
|
-
uploadSessionId: session.uploadSessionId,
|
|
25
|
-
edgeBaseUrl: session.edgeBaseUrl,
|
|
26
|
-
objectKey: session.objectKey,
|
|
27
|
-
partSizeBytes: session.partSizeBytes,
|
|
28
|
-
maxBytes: session.maxBytes,
|
|
29
|
-
expiresAt: session.expiresAt
|
|
30
|
-
};
|
|
31
|
-
return {
|
|
32
|
-
apiProjectId: data.apiProjectId,
|
|
33
|
-
upload,
|
|
34
|
-
objectPath: data.objectPath ?? session.objectKey,
|
|
35
|
-
expiresAt: data.expiresAt ?? session.expiresAt,
|
|
36
|
-
uploadCompletion
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
function parseCompleteProjectUploadResponse(data) {
|
|
40
|
-
const sizeBytes = data?.sizeBytes;
|
|
41
|
-
return {
|
|
42
|
-
apiProjectId: data?.apiProjectId,
|
|
43
|
-
status: data?.status ?? "uploaded",
|
|
44
|
-
sizeBytes: typeof sizeBytes === "number" ? sizeBytes : null
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
function parseProjectSummary(data) {
|
|
48
|
-
return {
|
|
49
|
-
apiProjectId: data.apiProjectId,
|
|
50
|
-
status: data.status || "uploading",
|
|
51
|
-
originalFileName: data.originalFileName ?? null,
|
|
52
|
-
contentType: data.contentType ?? null,
|
|
53
|
-
hasVideo: Boolean(data.hasVideo),
|
|
54
|
-
generationCount: Number(data.generationCount || 0),
|
|
55
|
-
createdAt: data.createdAt ?? null,
|
|
56
|
-
updatedAt: data.updatedAt ?? null
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
function parseListProjectsResponse(data) {
|
|
60
|
-
const items = Array.isArray(data?.projects) ? data.projects : [];
|
|
61
|
-
return { projects: items.filter(Boolean).map(parseProjectSummary) };
|
|
62
|
-
}
|
|
63
|
-
function parseCreateGenerationResponse(data) {
|
|
64
|
-
return {
|
|
65
|
-
generationId: data.generationId,
|
|
66
|
-
apiProjectId: data.apiProjectId,
|
|
67
|
-
modelKey: data.modelKey,
|
|
68
|
-
status: data.status,
|
|
69
|
-
...(data.idempotentReplay == null
|
|
70
|
-
? {}
|
|
71
|
-
: { idempotentReplay: Boolean(data.idempotentReplay) })
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
function parseProjectGenerationSummary(data) {
|
|
75
|
-
const progress = data.progress;
|
|
76
|
-
return {
|
|
77
|
-
generationId: data.generationId,
|
|
78
|
-
status: data.status || "queued",
|
|
79
|
-
modelKey: data.modelKey ?? null,
|
|
80
|
-
progress: progress != null ? Number(progress) : null,
|
|
81
|
-
createdAt: data.createdAt ?? null,
|
|
82
|
-
updatedAt: data.updatedAt ?? null
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
function parseListProjectGenerationsResponse(data) {
|
|
86
|
-
const items = Array.isArray(data?.generations) ? data.generations : [];
|
|
87
|
-
return {
|
|
88
|
-
apiProjectId: data.apiProjectId,
|
|
89
|
-
generations: items.filter(Boolean).map(parseProjectGenerationSummary)
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
function parseGenerationProgressStage(data) {
|
|
93
|
-
return {
|
|
94
|
-
jobId: data?.jobId ?? null,
|
|
95
|
-
jobState: data?.jobState ?? null,
|
|
96
|
-
status: data?.status || "pending",
|
|
97
|
-
progress: Number(data?.progress || 0),
|
|
98
|
-
statusMessage: data?.statusMessage ?? null,
|
|
99
|
-
error: data?.error ?? null,
|
|
100
|
-
errorDetails: data?.errorDetails ?? null
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
function parseGenerationProgressResponse(data) {
|
|
104
|
-
const restoredVideo = data?.restoredVideo;
|
|
105
|
-
const transcription = parseGenerationTranscription(data?.transcription);
|
|
106
|
-
const stageProgress = parseGenerationStageProgress(data?.stageProgress);
|
|
107
|
-
const queue = parseGenerationQueueStatus(data?.queue);
|
|
108
|
-
return {
|
|
109
|
-
generationId: data.generationId,
|
|
110
|
-
apiProjectId: data.apiProjectId,
|
|
111
|
-
status: data.status,
|
|
112
|
-
hasVideo: Boolean(data.hasVideo),
|
|
113
|
-
preProcessing: parseGenerationProgressStage(data.preProcessing),
|
|
114
|
-
inference: parseGenerationProgressStage(data.inference),
|
|
115
|
-
restoredVideo: restoredVideo ? parseGenerationProgressStage(restoredVideo) : null,
|
|
116
|
-
...(typeof data?.stage === "string" ? { stage: data.stage } : {}),
|
|
117
|
-
...(stageProgress ? { stageProgress } : {}),
|
|
118
|
-
...(queue ? { queue } : {}),
|
|
119
|
-
...(transcription ? { transcription } : {}),
|
|
120
|
-
warnings: parseGenerationWarnings(data?.warnings),
|
|
121
|
-
error: data.error ?? null,
|
|
122
|
-
errorDetails: data.errorDetails ?? null,
|
|
123
|
-
...(typeof data?.retryable === "boolean" ? { retryable: data.retryable } : {})
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
function parseGenerationDownloadResponse(data) {
|
|
127
|
-
return {
|
|
128
|
-
generationId: data.generationId,
|
|
129
|
-
apiProjectId: data.apiProjectId,
|
|
130
|
-
downloadType: data.downloadType,
|
|
131
|
-
downloadUrl: data.downloadUrl,
|
|
132
|
-
fileName: data.fileName,
|
|
133
|
-
storagePath: data.storagePath,
|
|
134
|
-
mimeType: data.mimeType
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
function parseWebhookTestEventResponse(data) {
|
|
138
|
-
return {
|
|
139
|
-
svixMessageId: data.svixMessageId,
|
|
140
|
-
eventId: data.eventId,
|
|
141
|
-
eventType: data.eventType,
|
|
142
|
-
mode: data.mode ?? null,
|
|
143
|
-
apiKeyId: data.apiKeyId ?? null
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
function parseAccountSettingsResponse(data) {
|
|
147
|
-
return {
|
|
148
|
-
apiKeyId: data?.apiKeyId ?? null,
|
|
149
|
-
account: data?.account && typeof data.account === "object" ? data.account : {}
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
function parseApiKeyResponse(data) {
|
|
153
|
-
return {
|
|
154
|
-
key: data?.key,
|
|
155
|
-
keyId: data?.keyId,
|
|
156
|
-
label: data?.label ?? "",
|
|
157
|
-
status: data?.status ?? "active",
|
|
158
|
-
keyPrefix: data?.keyPrefix ?? "",
|
|
159
|
-
role: data?.role ?? "scoped",
|
|
160
|
-
scopes: Array.isArray(data?.scopes) ? data.scopes.map(String) : [],
|
|
161
|
-
resourceBounds: data?.resourceBounds && typeof data.resourceBounds === "object" ? data.resourceBounds : {},
|
|
162
|
-
parentKeyId: data?.parentKeyId ?? null,
|
|
163
|
-
createdAt: data?.createdAt ?? null,
|
|
164
|
-
rotatedAt: data?.rotatedAt ?? null,
|
|
165
|
-
revokedAt: data?.revokedAt ?? null,
|
|
166
|
-
permissions: data?.permissions && typeof data.permissions === "object" ? data.permissions : undefined
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
function parseApiKeysListResponse(data) {
|
|
170
|
-
const items = Array.isArray(data?.keys) ? data.keys : [];
|
|
171
|
-
return { keys: items.filter(Boolean).map(parseApiKeyResponse) };
|
|
172
|
-
}
|
|
173
|
-
function parseUsageSummaryResponse(data) {
|
|
174
|
-
return {
|
|
175
|
-
usage: data?.usage && typeof data.usage === "object" ? data.usage : {},
|
|
176
|
-
billing: data?.billing && typeof data.billing === "object" ? data.billing : {}
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
function parseWebhookConfigureResponse(data) {
|
|
180
|
-
return {
|
|
181
|
-
webhook: data?.webhook && typeof data.webhook === "object" ? data.webhook : {}
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
function parseGenerationWebhookEvent(data) {
|
|
185
|
-
const transcription = parseGenerationTranscription(data?.transcription);
|
|
186
|
-
const warnings = parseGenerationWarnings(data?.warnings);
|
|
187
|
-
return {
|
|
188
|
-
eventType: data.eventType,
|
|
189
|
-
eventId: data.eventId,
|
|
190
|
-
createdAt: data.createdAt,
|
|
191
|
-
apiKeyId: data.apiKeyId,
|
|
192
|
-
apiProjectId: data.apiProjectId ?? null,
|
|
193
|
-
generationId: data.generationId,
|
|
194
|
-
status: data.status,
|
|
195
|
-
hasVideo: data.hasVideo ?? null,
|
|
196
|
-
modelKey: data.modelKey ?? null,
|
|
197
|
-
...(transcription ? { transcription } : {}),
|
|
198
|
-
...(warnings.length > 0 ? { warnings } : {}),
|
|
199
|
-
error: data.error ?? null,
|
|
200
|
-
errorDetails: data.errorDetails ?? null,
|
|
201
|
-
...(typeof data?.retryable === "boolean" ? { retryable: data.retryable } : {})
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
const optionalNumber = (value) => typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
205
|
-
function parseGenerationStageProgress(data) {
|
|
206
|
-
if (data == null || typeof data !== "object" || Array.isArray(data)) {
|
|
207
|
-
return undefined;
|
|
208
|
-
}
|
|
209
|
-
const source = data;
|
|
210
|
-
const progress = {};
|
|
211
|
-
for (const key of [
|
|
212
|
-
"overallPercent",
|
|
213
|
-
"stagePercent",
|
|
214
|
-
"bytesDone",
|
|
215
|
-
"bytesTotal",
|
|
216
|
-
"availableThroughSeconds",
|
|
217
|
-
"durationSeconds"
|
|
218
|
-
]) {
|
|
219
|
-
const value = optionalNumber(source[key]);
|
|
220
|
-
if (value != null) {
|
|
221
|
-
progress[key] = value;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
return progress;
|
|
225
|
-
}
|
|
226
|
-
function parseGenerationQueueStatus(data) {
|
|
227
|
-
if (data == null || typeof data !== "object" || Array.isArray(data)) {
|
|
228
|
-
return undefined;
|
|
229
|
-
}
|
|
230
|
-
const source = data;
|
|
231
|
-
return {
|
|
232
|
-
position: optionalNumber(source.position),
|
|
233
|
-
connectedWorkers: optionalNumber(source.connectedWorkers),
|
|
234
|
-
idleWorkers: optionalNumber(source.idleWorkers),
|
|
235
|
-
busyWorkers: optionalNumber(source.busyWorkers),
|
|
236
|
-
waitReason: typeof source.waitReason === "string" ? source.waitReason : null,
|
|
237
|
-
message: typeof source.message === "string" ? source.message : ""
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
function parseGenerationTranscription(data) {
|
|
241
|
-
if (data == null || typeof data !== "object" || !("status" in data)) {
|
|
242
|
-
return undefined;
|
|
243
|
-
}
|
|
244
|
-
const { status } = data;
|
|
245
|
-
if (status === "pending" || status === "available" || status === "unavailable") {
|
|
246
|
-
return { status };
|
|
247
|
-
}
|
|
248
|
-
return undefined;
|
|
249
|
-
}
|
|
250
|
-
/** Keeps the warnings with a known code and well-formed fields; anything else in the array is dropped. */
|
|
251
|
-
function parseGenerationWarnings(data) {
|
|
252
|
-
if (!Array.isArray(data)) {
|
|
253
|
-
return [];
|
|
254
|
-
}
|
|
255
|
-
const warnings = [];
|
|
256
|
-
for (const item of data) {
|
|
257
|
-
if (item == null || typeof item !== "object" || Array.isArray(item)) {
|
|
258
|
-
continue;
|
|
259
|
-
}
|
|
260
|
-
const { code, languages, message } = item;
|
|
261
|
-
if (code !== "unsupported_language" || !Array.isArray(languages) || typeof message !== "string") {
|
|
262
|
-
continue;
|
|
263
|
-
}
|
|
264
|
-
warnings.push({
|
|
265
|
-
code,
|
|
266
|
-
languages: languages.filter((language) => typeof language === "string" && language !== ""),
|
|
267
|
-
message
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
return warnings;
|
|
271
|
-
}
|
|
272
|
-
function createAudioIsolationResult(project, generation) {
|
|
273
|
-
return { project, generation };
|
|
274
|
-
}
|