diffio 0.4.63 → 1.0.1
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
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { RequestOptions, Transport } from "../../core/transport";
|
|
2
|
+
import { type VerifySignatureOptions, type WebhookHeaders, type WebhookPayload } from "../../core/webhookSignature";
|
|
3
|
+
import type { ProjectShare, ProjectSharePublishParams, ProjectShareRevoked, Usage, UsageParams, WebhookEvent, WebhookPortal } from "../types";
|
|
4
|
+
export declare class SharesResource {
|
|
5
|
+
private readonly transport;
|
|
6
|
+
constructor(transport: Transport);
|
|
7
|
+
/** `PUT /v2/projects/{project_id}/share`: publishes a public, key-free view of the project's result. */
|
|
8
|
+
publish(projectId: string, params?: ProjectSharePublishParams, options?: RequestOptions): Promise<ProjectShare>;
|
|
9
|
+
/** `GET /v2/projects/{project_id}/share`: the published share (404 `share_not_found` when none). */
|
|
10
|
+
get(projectId: string, options?: RequestOptions): Promise<ProjectShare>;
|
|
11
|
+
/** `DELETE /v2/projects/{project_id}/share`: revokes the share; its URLs stop working. */
|
|
12
|
+
revoke(projectId: string, options?: RequestOptions): Promise<ProjectShareRevoked>;
|
|
13
|
+
/** `GET /v2/shares/{share_id}`: the public view anyone with the id can read. Needs no API key. */
|
|
14
|
+
getPublic(shareId: string, options?: RequestOptions): Promise<ProjectShare>;
|
|
15
|
+
}
|
|
16
|
+
export declare class UsageResource {
|
|
17
|
+
private readonly transport;
|
|
18
|
+
constructor(transport: Transport);
|
|
19
|
+
/** `GET /v2/usage`: generations, billable seconds and list price for a period (default this month). */
|
|
20
|
+
get(params?: UsageParams, options?: RequestOptions): Promise<Usage>;
|
|
21
|
+
}
|
|
22
|
+
export declare class WebhooksResource {
|
|
23
|
+
private readonly transport;
|
|
24
|
+
constructor(transport: Transport);
|
|
25
|
+
/**
|
|
26
|
+
* `POST /v2/webhooks/portal`: a short-lived link to the webhook portal, where you add endpoints, pick
|
|
27
|
+
* events and copy each endpoint's signing secret. Needs a key with write permission. The portal belongs
|
|
28
|
+
* to the account, so this call never sends `Diffio-End-User`, even when the client sets `endUser`.
|
|
29
|
+
*/
|
|
30
|
+
portal(options?: RequestOptions): Promise<WebhookPortal>;
|
|
31
|
+
/**
|
|
32
|
+
* Checks a delivery's `svix-id`, `svix-timestamp` and `svix-signature` against the endpoint's
|
|
33
|
+
* `whsec_` secret (Node crypto) and returns the parsed event. Pass the raw body as received.
|
|
34
|
+
*/
|
|
35
|
+
verifySignature(payload: WebhookPayload, headers: WebhookHeaders, secret: string, options?: VerifySignatureOptions): WebhookEvent;
|
|
36
|
+
/** The same check with WebCrypto, for browsers, edge runtimes, Deno and Bun. */
|
|
37
|
+
verifySignatureAsync(payload: WebhookPayload, headers: WebhookHeaders, secret: string, options?: VerifySignatureOptions): Promise<WebhookEvent>;
|
|
38
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Shares, usage and webhooks.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.WebhooksResource = exports.UsageResource = exports.SharesResource = void 0;
|
|
5
|
+
const url_1 = require("../../core/url");
|
|
6
|
+
const webhookSignature_1 = require("../../core/webhookSignature");
|
|
7
|
+
class SharesResource {
|
|
8
|
+
constructor(transport) {
|
|
9
|
+
this.transport = transport;
|
|
10
|
+
}
|
|
11
|
+
/** `PUT /v2/projects/{project_id}/share`: publishes a public, key-free view of the project's result. */
|
|
12
|
+
async publish(projectId, params = {}, options) {
|
|
13
|
+
return this.transport.request({
|
|
14
|
+
method: "PUT",
|
|
15
|
+
path: `/projects/${(0, url_1.segment)(projectId, "projectId")}/share`,
|
|
16
|
+
body: params,
|
|
17
|
+
idempotent: true,
|
|
18
|
+
options
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/** `GET /v2/projects/{project_id}/share`: the published share (404 `share_not_found` when none). */
|
|
22
|
+
async get(projectId, options) {
|
|
23
|
+
return this.transport.request({
|
|
24
|
+
method: "GET",
|
|
25
|
+
path: `/projects/${(0, url_1.segment)(projectId, "projectId")}/share`,
|
|
26
|
+
idempotent: true,
|
|
27
|
+
options
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/** `DELETE /v2/projects/{project_id}/share`: revokes the share; its URLs stop working. */
|
|
31
|
+
async revoke(projectId, options) {
|
|
32
|
+
return this.transport.request({
|
|
33
|
+
method: "DELETE",
|
|
34
|
+
path: `/projects/${(0, url_1.segment)(projectId, "projectId")}/share`,
|
|
35
|
+
idempotent: true,
|
|
36
|
+
options
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/** `GET /v2/shares/{share_id}`: the public view anyone with the id can read. Needs no API key. */
|
|
40
|
+
async getPublic(shareId, options) {
|
|
41
|
+
return this.transport.request({
|
|
42
|
+
method: "GET",
|
|
43
|
+
path: `/shares/${(0, url_1.segment)(shareId, "shareId")}`,
|
|
44
|
+
idempotent: true,
|
|
45
|
+
noAuth: true,
|
|
46
|
+
options
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.SharesResource = SharesResource;
|
|
51
|
+
class UsageResource {
|
|
52
|
+
constructor(transport) {
|
|
53
|
+
this.transport = transport;
|
|
54
|
+
}
|
|
55
|
+
/** `GET /v2/usage`: generations, billable seconds and list price for a period (default this month). */
|
|
56
|
+
async get(params = {}, options) {
|
|
57
|
+
return this.transport.request({
|
|
58
|
+
method: "GET",
|
|
59
|
+
path: `/usage${(0, url_1.queryString)({ start: params.start, end: params.end })}`,
|
|
60
|
+
idempotent: true,
|
|
61
|
+
options
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.UsageResource = UsageResource;
|
|
66
|
+
class WebhooksResource {
|
|
67
|
+
constructor(transport) {
|
|
68
|
+
this.transport = transport;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* `POST /v2/webhooks/portal`: a short-lived link to the webhook portal, where you add endpoints, pick
|
|
72
|
+
* events and copy each endpoint's signing secret. Needs a key with write permission. The portal belongs
|
|
73
|
+
* to the account, so this call never sends `Diffio-End-User`, even when the client sets `endUser`.
|
|
74
|
+
*/
|
|
75
|
+
async portal(options) {
|
|
76
|
+
return this.transport.request({
|
|
77
|
+
method: "POST",
|
|
78
|
+
path: "/webhooks/portal",
|
|
79
|
+
idempotent: true,
|
|
80
|
+
accountLevel: true,
|
|
81
|
+
options
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Checks a delivery's `svix-id`, `svix-timestamp` and `svix-signature` against the endpoint's
|
|
86
|
+
* `whsec_` secret (Node crypto) and returns the parsed event. Pass the raw body as received.
|
|
87
|
+
*/
|
|
88
|
+
verifySignature(payload, headers, secret, options) {
|
|
89
|
+
return (0, webhookSignature_1.verifyWebhookSignature)(payload, headers, secret, options);
|
|
90
|
+
}
|
|
91
|
+
/** The same check with WebCrypto, for browsers, edge runtimes, Deno and Bun. */
|
|
92
|
+
verifySignatureAsync(payload, headers, secret, options) {
|
|
93
|
+
return (0, webhookSignature_1.verifyWebhookSignatureAsync)(payload, headers, secret, options);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.WebhooksResource = WebhooksResource;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { RequestOptions, Transport } from "../../core/transport";
|
|
2
|
+
import { type WaitOptions } from "../../core/poll";
|
|
3
|
+
import type { Generation, GenerationExport, GenerationExportCreateParams, GenerationExportGetParams, GenerationMix, GenerationMixSaveParams, Transcript, TranscriptAssistantTurn, TranscriptAssistantTurnCreateParams, TranscriptDraft, TranscriptDraftDeleteParams, TranscriptDraftDeleted, TranscriptDraftSaveParams, TranscriptEditCreateParams, TranscriptEditEstimate, TranscriptGetParams } from "../types";
|
|
4
|
+
export declare class EditsResource {
|
|
5
|
+
private readonly transport;
|
|
6
|
+
constructor(transport: Transport);
|
|
7
|
+
/** `POST .../edits/estimate`: what an edit would bill; creates and charges nothing. */
|
|
8
|
+
estimate(projectId: string, generationId: string, params: TranscriptEditCreateParams, options?: RequestOptions): Promise<TranscriptEditEstimate>;
|
|
9
|
+
/**
|
|
10
|
+
* `POST .../edits`: re-restores only the changed words of a finished Pro result. Returns the new
|
|
11
|
+
* generation (`kind: "edit"`); follow it with `generations.wait`.
|
|
12
|
+
*/
|
|
13
|
+
create(projectId: string, generationId: string, params: TranscriptEditCreateParams, options?: RequestOptions): Promise<Generation>;
|
|
14
|
+
}
|
|
15
|
+
export declare class MixResource {
|
|
16
|
+
private readonly transport;
|
|
17
|
+
constructor(transport: Transport);
|
|
18
|
+
/** `GET .../mix`: the saved balance of the separated speech and background tracks. */
|
|
19
|
+
get(projectId: string, generationId: string, options?: RequestOptions): Promise<GenerationMix>;
|
|
20
|
+
/** `PUT .../mix`: saves `background_gain` (0 to 1) and `leveling`; send `revision` to refuse stale saves. */
|
|
21
|
+
save(projectId: string, generationId: string, params: GenerationMixSaveParams, options?: RequestOptions): Promise<GenerationMix>;
|
|
22
|
+
}
|
|
23
|
+
export declare class ExportsResource {
|
|
24
|
+
private readonly transport;
|
|
25
|
+
constructor(transport: Transport);
|
|
26
|
+
/** `POST .../exports`: renders speech, background, a mix, both (zip) or the original as a file. */
|
|
27
|
+
create(projectId: string, generationId: string, params: GenerationExportCreateParams, options?: RequestOptions): Promise<GenerationExport>;
|
|
28
|
+
/** `GET .../exports/{export_id}`: its status and, once `ready`, a fresh `url`. */
|
|
29
|
+
get(projectId: string, generationId: string, exportId: string, params?: GenerationExportGetParams, options?: RequestOptions): Promise<GenerationExport>;
|
|
30
|
+
/** Polls `get` until the export is `ready` (default timeout 600 s). */
|
|
31
|
+
wait(projectId: string, generationId: string, exportId: string, options?: WaitOptions<GenerationExport> & RequestOptions & GenerationExportGetParams): Promise<GenerationExport>;
|
|
32
|
+
}
|
|
33
|
+
export declare class TranscriptsResource {
|
|
34
|
+
private readonly transport;
|
|
35
|
+
constructor(transport: Transport);
|
|
36
|
+
/** `GET .../transcript`: the word-timed transcript of a finished generation. */
|
|
37
|
+
get(projectId: string, generationId: string, params?: TranscriptGetParams, options?: RequestOptions): Promise<Transcript>;
|
|
38
|
+
/** `GET .../transcript/draft`: the saved editor state (`data` is null when nothing is saved). */
|
|
39
|
+
getDraft(projectId: string, generationId: string, options?: RequestOptions): Promise<TranscriptDraft>;
|
|
40
|
+
/** `PUT .../transcript/draft`: saves `data`; send the `revision` you read to refuse stale saves. */
|
|
41
|
+
saveDraft(projectId: string, generationId: string, params: TranscriptDraftSaveParams, options?: RequestOptions): Promise<TranscriptDraft>;
|
|
42
|
+
/** `DELETE .../transcript/draft`: deletes the draft (`revision` makes it conditional). */
|
|
43
|
+
deleteDraft(projectId: string, generationId: string, params?: TranscriptDraftDeleteParams, options?: RequestOptions): Promise<TranscriptDraftDeleted>;
|
|
44
|
+
}
|
|
45
|
+
export declare class AssistantResource {
|
|
46
|
+
private readonly transport;
|
|
47
|
+
constructor(transport: Transport);
|
|
48
|
+
/** `POST .../transcript/assistant/turns`: asks the edit assistant; answers 202 with `status: "processing"`. */
|
|
49
|
+
createTurn(projectId: string, generationId: string, params: TranscriptAssistantTurnCreateParams, options?: RequestOptions): Promise<TranscriptAssistantTurn>;
|
|
50
|
+
/** `GET .../transcript/assistant/turns/{turn_id}`. */
|
|
51
|
+
getTurn(projectId: string, generationId: string, turnId: string, options?: RequestOptions): Promise<TranscriptAssistantTurn>;
|
|
52
|
+
/** Polls `getTurn` until the turn is `complete` (default timeout 600 s). */
|
|
53
|
+
waitTurn(projectId: string, generationId: string, turnId: string, options?: WaitOptions<TranscriptAssistantTurn> & RequestOptions): Promise<TranscriptAssistantTurn>;
|
|
54
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Transcript edits, the saved mix, exports, transcripts and drafts, and the edit assistant.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.AssistantResource = exports.TranscriptsResource = exports.ExportsResource = exports.MixResource = exports.EditsResource = void 0;
|
|
5
|
+
const url_1 = require("../../core/url");
|
|
6
|
+
const poll_1 = require("../../core/poll");
|
|
7
|
+
const generations_1 = require("./generations");
|
|
8
|
+
const DEFAULT_EXPORT_WAIT_TIMEOUT_SECONDS = 600;
|
|
9
|
+
const DEFAULT_TURN_WAIT_TIMEOUT_SECONDS = 600;
|
|
10
|
+
class EditsResource {
|
|
11
|
+
constructor(transport) {
|
|
12
|
+
this.transport = transport;
|
|
13
|
+
}
|
|
14
|
+
/** `POST .../edits/estimate`: what an edit would bill; creates and charges nothing. */
|
|
15
|
+
async estimate(projectId, generationId, params, options) {
|
|
16
|
+
return this.transport.request({
|
|
17
|
+
method: "POST",
|
|
18
|
+
path: `${(0, generations_1.generationPath)(projectId, generationId)}/edits/estimate`,
|
|
19
|
+
body: params ?? {},
|
|
20
|
+
idempotent: true,
|
|
21
|
+
options
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* `POST .../edits`: re-restores only the changed words of a finished Pro result. Returns the new
|
|
26
|
+
* generation (`kind: "edit"`); follow it with `generations.wait`.
|
|
27
|
+
*/
|
|
28
|
+
async create(projectId, generationId, params, options) {
|
|
29
|
+
return this.transport.request({
|
|
30
|
+
method: "POST",
|
|
31
|
+
path: `${(0, generations_1.generationPath)(projectId, generationId)}/edits`,
|
|
32
|
+
body: params ?? {},
|
|
33
|
+
idempotent: false,
|
|
34
|
+
acceptsIdempotencyKey: true,
|
|
35
|
+
options
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.EditsResource = EditsResource;
|
|
40
|
+
class MixResource {
|
|
41
|
+
constructor(transport) {
|
|
42
|
+
this.transport = transport;
|
|
43
|
+
}
|
|
44
|
+
/** `GET .../mix`: the saved balance of the separated speech and background tracks. */
|
|
45
|
+
async get(projectId, generationId, options) {
|
|
46
|
+
return this.transport.request({
|
|
47
|
+
method: "GET",
|
|
48
|
+
path: `${(0, generations_1.generationPath)(projectId, generationId)}/mix`,
|
|
49
|
+
idempotent: true,
|
|
50
|
+
options
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/** `PUT .../mix`: saves `background_gain` (0 to 1) and `leveling`; send `revision` to refuse stale saves. */
|
|
54
|
+
async save(projectId, generationId, params, options) {
|
|
55
|
+
return this.transport.request({
|
|
56
|
+
method: "PUT",
|
|
57
|
+
path: `${(0, generations_1.generationPath)(projectId, generationId)}/mix`,
|
|
58
|
+
body: params,
|
|
59
|
+
idempotent: true,
|
|
60
|
+
options
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.MixResource = MixResource;
|
|
65
|
+
class ExportsResource {
|
|
66
|
+
constructor(transport) {
|
|
67
|
+
this.transport = transport;
|
|
68
|
+
}
|
|
69
|
+
/** `POST .../exports`: renders speech, background, a mix, both (zip) or the original as a file. */
|
|
70
|
+
async create(projectId, generationId, params, options) {
|
|
71
|
+
return this.transport.request({
|
|
72
|
+
method: "POST",
|
|
73
|
+
path: `${(0, generations_1.generationPath)(projectId, generationId)}/exports`,
|
|
74
|
+
body: params,
|
|
75
|
+
// The same recipe returns the same export, so repeating it is safe.
|
|
76
|
+
idempotent: true,
|
|
77
|
+
options
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/** `GET .../exports/{export_id}`: its status and, once `ready`, a fresh `url`. */
|
|
81
|
+
async get(projectId, generationId, exportId, params = {}, options) {
|
|
82
|
+
return this.transport.request({
|
|
83
|
+
method: "GET",
|
|
84
|
+
path: `${(0, generations_1.generationPath)(projectId, generationId)}/exports/${(0, url_1.segment)(exportId, "exportId")}${(0, url_1.queryString)({ file_name: params.file_name })}`,
|
|
85
|
+
idempotent: true,
|
|
86
|
+
options
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/** Polls `get` until the export is `ready` (default timeout 600 s). */
|
|
90
|
+
async wait(projectId, generationId, exportId, options = {}) {
|
|
91
|
+
const { timeout, pollInterval, onProgress, file_name, ...requestOptions } = options;
|
|
92
|
+
return (0, poll_1.pollUntil)(() => this.get(projectId, generationId, exportId, { file_name }, requestOptions), (item) => item.status === "ready", "export", { timeout, pollInterval, onProgress, signal: options.signal, defaultTimeout: DEFAULT_EXPORT_WAIT_TIMEOUT_SECONDS });
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.ExportsResource = ExportsResource;
|
|
96
|
+
class TranscriptsResource {
|
|
97
|
+
constructor(transport) {
|
|
98
|
+
this.transport = transport;
|
|
99
|
+
}
|
|
100
|
+
/** `GET .../transcript`: the word-timed transcript of a finished generation. */
|
|
101
|
+
async get(projectId, generationId, params = {}, options) {
|
|
102
|
+
return this.transport.request({
|
|
103
|
+
method: "GET",
|
|
104
|
+
path: `${(0, generations_1.generationPath)(projectId, generationId)}/transcript${(0, url_1.queryString)({ preview_seconds: params.preview_seconds })}`,
|
|
105
|
+
idempotent: true,
|
|
106
|
+
options
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/** `GET .../transcript/draft`: the saved editor state (`data` is null when nothing is saved). */
|
|
110
|
+
async getDraft(projectId, generationId, options) {
|
|
111
|
+
return this.transport.request({
|
|
112
|
+
method: "GET",
|
|
113
|
+
path: `${(0, generations_1.generationPath)(projectId, generationId)}/transcript/draft`,
|
|
114
|
+
idempotent: true,
|
|
115
|
+
options
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/** `PUT .../transcript/draft`: saves `data`; send the `revision` you read to refuse stale saves. */
|
|
119
|
+
async saveDraft(projectId, generationId, params, options) {
|
|
120
|
+
return this.transport.request({
|
|
121
|
+
method: "PUT",
|
|
122
|
+
path: `${(0, generations_1.generationPath)(projectId, generationId)}/transcript/draft`,
|
|
123
|
+
body: params,
|
|
124
|
+
idempotent: true,
|
|
125
|
+
options
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
/** `DELETE .../transcript/draft`: deletes the draft (`revision` makes it conditional). */
|
|
129
|
+
async deleteDraft(projectId, generationId, params = {}, options) {
|
|
130
|
+
return this.transport.request({
|
|
131
|
+
method: "DELETE",
|
|
132
|
+
path: `${(0, generations_1.generationPath)(projectId, generationId)}/transcript/draft${(0, url_1.queryString)({ revision: params.revision })}`,
|
|
133
|
+
idempotent: true,
|
|
134
|
+
options
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
exports.TranscriptsResource = TranscriptsResource;
|
|
139
|
+
class AssistantResource {
|
|
140
|
+
constructor(transport) {
|
|
141
|
+
this.transport = transport;
|
|
142
|
+
}
|
|
143
|
+
/** `POST .../transcript/assistant/turns`: asks the edit assistant; answers 202 with `status: "processing"`. */
|
|
144
|
+
async createTurn(projectId, generationId, params, options) {
|
|
145
|
+
return this.transport.request({
|
|
146
|
+
method: "POST",
|
|
147
|
+
path: `${(0, generations_1.generationPath)(projectId, generationId)}/transcript/assistant/turns`,
|
|
148
|
+
body: params,
|
|
149
|
+
idempotent: false,
|
|
150
|
+
options
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
/** `GET .../transcript/assistant/turns/{turn_id}`. */
|
|
154
|
+
async getTurn(projectId, generationId, turnId, options) {
|
|
155
|
+
return this.transport.request({
|
|
156
|
+
method: "GET",
|
|
157
|
+
path: `${(0, generations_1.generationPath)(projectId, generationId)}/transcript/assistant/turns/${(0, url_1.segment)(turnId, "turnId")}`,
|
|
158
|
+
idempotent: true,
|
|
159
|
+
options
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
/** Polls `getTurn` until the turn is `complete` (default timeout 600 s). */
|
|
163
|
+
async waitTurn(projectId, generationId, turnId, options = {}) {
|
|
164
|
+
const { timeout, pollInterval, onProgress, ...requestOptions } = options;
|
|
165
|
+
return (0, poll_1.pollUntil)(() => this.getTurn(projectId, generationId, turnId, requestOptions), (turn) => turn.status === "complete", "assistant turn", { timeout, pollInterval: pollInterval ?? 1.5, onProgress, signal: options.signal, defaultTimeout: DEFAULT_TURN_WAIT_TIMEOUT_SECONDS });
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
exports.AssistantResource = AssistantResource;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type RequestOptions, type Transport } from "../../core/transport";
|
|
2
|
+
import { PagePromise } from "../../core/pagination";
|
|
3
|
+
import { type WaitOptions } from "../../core/poll";
|
|
4
|
+
import type { Generation, GenerationCreateParams, GenerationFileName, GenerationMedia, GenerationMediaParams, ListParams } from "../types";
|
|
5
|
+
/** How long `wait` polls by default; long recordings queue and run for a while. */
|
|
6
|
+
export declare const DEFAULT_GENERATION_WAIT_TIMEOUT_SECONDS = 3600;
|
|
7
|
+
export declare const generationPath: (projectId: string, generationId: string) => string;
|
|
8
|
+
export interface GenerationDownloadOptions extends RequestOptions {
|
|
9
|
+
/** Which file of `GET .../media` to fetch (default `audio`, the restored audio). */
|
|
10
|
+
file?: GenerationFileName;
|
|
11
|
+
/** Node: write the file here (streamed) instead of returning its bytes. */
|
|
12
|
+
path?: string;
|
|
13
|
+
}
|
|
14
|
+
/** What `download` returns. `data` holds the bytes when no `path` was given. */
|
|
15
|
+
export interface GenerationDownload {
|
|
16
|
+
file: string;
|
|
17
|
+
url: string;
|
|
18
|
+
path: string | null;
|
|
19
|
+
data: Uint8Array | null;
|
|
20
|
+
size_bytes: number;
|
|
21
|
+
content_type: string | null;
|
|
22
|
+
}
|
|
23
|
+
export declare class GenerationsResource {
|
|
24
|
+
private readonly transport;
|
|
25
|
+
constructor(transport: Transport);
|
|
26
|
+
/**
|
|
27
|
+
* `POST /v2/projects/{project_id}/generations`: starts a restore with `model` (`diffio-flash`,
|
|
28
|
+
* `diffio-pro`, ...). Sent before the upload is ready it waits in `queued` and starts by itself.
|
|
29
|
+
*/
|
|
30
|
+
create(projectId: string, params: GenerationCreateParams, options?: RequestOptions): Promise<Generation>;
|
|
31
|
+
/** `GET /v2/projects/{project_id}/generations`: newest first; `for await` walks every page. */
|
|
32
|
+
list(projectId: string, params?: ListParams, options?: RequestOptions): PagePromise<Generation>;
|
|
33
|
+
/** `GET /v2/projects/{project_id}/generations/{generation_id}`. */
|
|
34
|
+
get(projectId: string, generationId: string, options?: RequestOptions): Promise<Generation>;
|
|
35
|
+
/**
|
|
36
|
+
* Polls `get` until the generation is `complete` and returns it. Throws DiffioResourceFailedError
|
|
37
|
+
* (with `error.code`) when it fails and DiffioTimeoutError after `timeout` seconds (default 3600).
|
|
38
|
+
*/
|
|
39
|
+
wait(projectId: string, generationId: string, options?: WaitOptions<Generation> & RequestOptions): Promise<Generation>;
|
|
40
|
+
/**
|
|
41
|
+
* `GET .../media`: URLs for the generation's files (`audio`, `video`, `hls_master`, `transcript`,
|
|
42
|
+
* `original`, ...). They need no API key and expire at `expires_at` (6 hours).
|
|
43
|
+
*/
|
|
44
|
+
media(projectId: string, generationId: string, params?: GenerationMediaParams, options?: RequestOptions): Promise<GenerationMedia>;
|
|
45
|
+
/**
|
|
46
|
+
* Fetches one result file through `media` (default `audio`). With `path` (Node) it streams to that file;
|
|
47
|
+
* otherwise it returns the bytes in `data`.
|
|
48
|
+
*/
|
|
49
|
+
download(projectId: string, generationId: string, options?: GenerationDownloadOptions): Promise<GenerationDownload>;
|
|
50
|
+
/** GETs a signed media URL (no API key), retrying network failures and 5xx/429. */
|
|
51
|
+
private fetchMedia;
|
|
52
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GenerationsResource = exports.generationPath = exports.DEFAULT_GENERATION_WAIT_TIMEOUT_SECONDS = void 0;
|
|
4
|
+
const transport_1 = require("../../core/transport");
|
|
5
|
+
const pagination_1 = require("../../core/pagination");
|
|
6
|
+
const url_1 = require("../../core/url");
|
|
7
|
+
const poll_1 = require("../../core/poll");
|
|
8
|
+
const retry_1 = require("../../core/retry");
|
|
9
|
+
const files_1 = require("../../core/files");
|
|
10
|
+
const errors_1 = require("../../errors");
|
|
11
|
+
/** How long `wait` polls by default; long recordings queue and run for a while. */
|
|
12
|
+
exports.DEFAULT_GENERATION_WAIT_TIMEOUT_SECONDS = 3600;
|
|
13
|
+
const DEFAULT_DOWNLOAD_TIMEOUT_SECONDS = 600;
|
|
14
|
+
const generationPath = (projectId, generationId) => `/projects/${(0, url_1.segment)(projectId, "projectId")}/generations/${(0, url_1.segment)(generationId, "generationId")}`;
|
|
15
|
+
exports.generationPath = generationPath;
|
|
16
|
+
class GenerationsResource {
|
|
17
|
+
constructor(transport) {
|
|
18
|
+
this.transport = transport;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* `POST /v2/projects/{project_id}/generations`: starts a restore with `model` (`diffio-flash`,
|
|
22
|
+
* `diffio-pro`, ...). Sent before the upload is ready it waits in `queued` and starts by itself.
|
|
23
|
+
*/
|
|
24
|
+
async create(projectId, params, options) {
|
|
25
|
+
if (!params || typeof params.model !== "string" || !params.model.trim())
|
|
26
|
+
throw new TypeError("model is required");
|
|
27
|
+
return this.transport.request({
|
|
28
|
+
method: "POST",
|
|
29
|
+
path: `/projects/${(0, url_1.segment)(projectId, "projectId")}/generations`,
|
|
30
|
+
body: params,
|
|
31
|
+
idempotent: false,
|
|
32
|
+
acceptsIdempotencyKey: true,
|
|
33
|
+
options
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/** `GET /v2/projects/{project_id}/generations`: newest first; `for await` walks every page. */
|
|
37
|
+
list(projectId, params = {}, options) {
|
|
38
|
+
const path = `/projects/${(0, url_1.segment)(projectId, "projectId")}/generations`;
|
|
39
|
+
return pagination_1.PagePromise.from(async () => {
|
|
40
|
+
const response = await this.transport.request({
|
|
41
|
+
method: "GET",
|
|
42
|
+
path: `${path}${(0, url_1.queryString)({ limit: params.limit, cursor: params.cursor })}`,
|
|
43
|
+
idempotent: true,
|
|
44
|
+
options
|
|
45
|
+
});
|
|
46
|
+
return new pagination_1.Page(response, async (cursor) => this.list(projectId, { ...params, cursor }, options));
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/** `GET /v2/projects/{project_id}/generations/{generation_id}`. */
|
|
50
|
+
async get(projectId, generationId, options) {
|
|
51
|
+
return this.transport.request({
|
|
52
|
+
method: "GET",
|
|
53
|
+
path: (0, exports.generationPath)(projectId, generationId),
|
|
54
|
+
idempotent: true,
|
|
55
|
+
options
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Polls `get` until the generation is `complete` and returns it. Throws DiffioResourceFailedError
|
|
60
|
+
* (with `error.code`) when it fails and DiffioTimeoutError after `timeout` seconds (default 3600).
|
|
61
|
+
*/
|
|
62
|
+
async wait(projectId, generationId, options = {}) {
|
|
63
|
+
const { timeout, pollInterval, onProgress, ...requestOptions } = options;
|
|
64
|
+
return (0, poll_1.pollUntil)(() => this.get(projectId, generationId, requestOptions), (generation) => generation.status === "complete", "generation", { timeout, pollInterval, onProgress, signal: options.signal, defaultTimeout: exports.DEFAULT_GENERATION_WAIT_TIMEOUT_SECONDS });
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* `GET .../media`: URLs for the generation's files (`audio`, `video`, `hls_master`, `transcript`,
|
|
68
|
+
* `original`, ...). They need no API key and expire at `expires_at` (6 hours).
|
|
69
|
+
*/
|
|
70
|
+
async media(projectId, generationId, params = {}, options) {
|
|
71
|
+
return this.transport.request({
|
|
72
|
+
method: "GET",
|
|
73
|
+
path: `${(0, exports.generationPath)(projectId, generationId)}/media${(0, url_1.queryString)({ preview_seconds: params.preview_seconds })}`,
|
|
74
|
+
idempotent: true,
|
|
75
|
+
options
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Fetches one result file through `media` (default `audio`). With `path` (Node) it streams to that file;
|
|
80
|
+
* otherwise it returns the bytes in `data`.
|
|
81
|
+
*/
|
|
82
|
+
async download(projectId, generationId, options = {}) {
|
|
83
|
+
const { file = "audio", path, ...requestOptions } = options;
|
|
84
|
+
const media = await this.media(projectId, generationId, {}, requestOptions);
|
|
85
|
+
const url = media.files[file];
|
|
86
|
+
if (!url) {
|
|
87
|
+
const available = Object.keys(media.files).sort().join(", ") || "none";
|
|
88
|
+
throw new errors_1.DiffioError(`Generation ${generationId} has no "${file}" file yet (status ${media.status}; files: ${available}).`);
|
|
89
|
+
}
|
|
90
|
+
const response = await this.fetchMedia(url, requestOptions);
|
|
91
|
+
const contentType = response.headers.get("content-type");
|
|
92
|
+
if (path) {
|
|
93
|
+
const written = await (0, files_1.writeResponseToFile)(response, path);
|
|
94
|
+
return { file, url, path, data: null, size_bytes: written, content_type: contentType };
|
|
95
|
+
}
|
|
96
|
+
const data = new Uint8Array(await response.arrayBuffer());
|
|
97
|
+
return { file, url, path: null, data, size_bytes: data.byteLength, content_type: contentType };
|
|
98
|
+
}
|
|
99
|
+
/** GETs a signed media URL (no API key), retrying network failures and 5xx/429. */
|
|
100
|
+
async fetchMedia(url, options) {
|
|
101
|
+
const { maxRetries, backoff } = this.transport.retryPolicy(options);
|
|
102
|
+
const timeoutMs = (options.timeout ?? DEFAULT_DOWNLOAD_TIMEOUT_SECONDS) * 1000;
|
|
103
|
+
for (let attempt = 0;; attempt += 1) {
|
|
104
|
+
let response;
|
|
105
|
+
try {
|
|
106
|
+
response = await (0, transport_1.fetchWithTimeout)(this.transport.fetchFn, url, { method: "GET" }, timeoutMs, options.signal);
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
if (options.signal?.aborted)
|
|
110
|
+
throw error;
|
|
111
|
+
if (attempt < maxRetries) {
|
|
112
|
+
await (0, retry_1.sleep)((0, retry_1.retryDelayMs)(attempt + 1, backoff), options.signal);
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (error instanceof errors_1.DiffioError)
|
|
116
|
+
throw error;
|
|
117
|
+
throw new errors_1.DiffioConnectionError(`Could not download ${url.split("?")[0]}: ${String(error?.message ?? error)}`, error);
|
|
118
|
+
}
|
|
119
|
+
if (response.ok)
|
|
120
|
+
return response;
|
|
121
|
+
if (attempt < maxRetries && retry_1.DEFAULT_RETRY_STATUS_CODES.includes(response.status)) {
|
|
122
|
+
await response.arrayBuffer().catch(() => undefined);
|
|
123
|
+
await (0, retry_1.sleep)((0, retry_1.retryDelayMs)(attempt + 1, backoff, response.headers.get("retry-after")), options.signal);
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
const text = await response.text().catch(() => "");
|
|
127
|
+
let body = text;
|
|
128
|
+
try {
|
|
129
|
+
body = JSON.parse(text);
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
body = text;
|
|
133
|
+
}
|
|
134
|
+
const error = body && typeof body === "object" ? body.error : undefined;
|
|
135
|
+
throw new errors_1.DiffioApiError({
|
|
136
|
+
status: response.status,
|
|
137
|
+
code: error?.code ?? (response.status === 404 ? "not_found" : "download_failed"),
|
|
138
|
+
message: error?.message ?? `The media download failed with HTTP ${response.status}.`,
|
|
139
|
+
headers: response.headers,
|
|
140
|
+
body
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.GenerationsResource = GenerationsResource;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export { UsageClient } from "./usage/client/Client";
|
|
7
|
-
export { WebhooksClient } from "./webhooks/client/Client";
|
|
1
|
+
export { ModelsResource } from "./models";
|
|
2
|
+
export { ProjectsResource, type ProjectUploadOptions } from "./projects";
|
|
3
|
+
export { GenerationsResource, DEFAULT_GENERATION_WAIT_TIMEOUT_SECONDS, type GenerationDownload, type GenerationDownloadOptions } from "./generations";
|
|
4
|
+
export { EditsResource, MixResource, ExportsResource, TranscriptsResource, AssistantResource } from "./editing";
|
|
5
|
+
export { SharesResource, UsageResource, WebhooksResource } from "./account";
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "
|
|
6
|
-
var
|
|
7
|
-
Object.defineProperty(exports, "
|
|
8
|
-
var
|
|
9
|
-
Object.defineProperty(exports, "
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
Object.defineProperty(exports, "
|
|
14
|
-
|
|
15
|
-
Object.defineProperty(exports, "
|
|
16
|
-
|
|
17
|
-
|
|
3
|
+
exports.WebhooksResource = exports.UsageResource = exports.SharesResource = exports.AssistantResource = exports.TranscriptsResource = exports.ExportsResource = exports.MixResource = exports.EditsResource = exports.DEFAULT_GENERATION_WAIT_TIMEOUT_SECONDS = exports.GenerationsResource = exports.ProjectsResource = exports.ModelsResource = void 0;
|
|
4
|
+
var models_1 = require("./models");
|
|
5
|
+
Object.defineProperty(exports, "ModelsResource", { enumerable: true, get: function () { return models_1.ModelsResource; } });
|
|
6
|
+
var projects_1 = require("./projects");
|
|
7
|
+
Object.defineProperty(exports, "ProjectsResource", { enumerable: true, get: function () { return projects_1.ProjectsResource; } });
|
|
8
|
+
var generations_1 = require("./generations");
|
|
9
|
+
Object.defineProperty(exports, "GenerationsResource", { enumerable: true, get: function () { return generations_1.GenerationsResource; } });
|
|
10
|
+
Object.defineProperty(exports, "DEFAULT_GENERATION_WAIT_TIMEOUT_SECONDS", { enumerable: true, get: function () { return generations_1.DEFAULT_GENERATION_WAIT_TIMEOUT_SECONDS; } });
|
|
11
|
+
var editing_1 = require("./editing");
|
|
12
|
+
Object.defineProperty(exports, "EditsResource", { enumerable: true, get: function () { return editing_1.EditsResource; } });
|
|
13
|
+
Object.defineProperty(exports, "MixResource", { enumerable: true, get: function () { return editing_1.MixResource; } });
|
|
14
|
+
Object.defineProperty(exports, "ExportsResource", { enumerable: true, get: function () { return editing_1.ExportsResource; } });
|
|
15
|
+
Object.defineProperty(exports, "TranscriptsResource", { enumerable: true, get: function () { return editing_1.TranscriptsResource; } });
|
|
16
|
+
Object.defineProperty(exports, "AssistantResource", { enumerable: true, get: function () { return editing_1.AssistantResource; } });
|
|
17
|
+
var account_1 = require("./account");
|
|
18
|
+
Object.defineProperty(exports, "SharesResource", { enumerable: true, get: function () { return account_1.SharesResource; } });
|
|
19
|
+
Object.defineProperty(exports, "UsageResource", { enumerable: true, get: function () { return account_1.UsageResource; } });
|
|
20
|
+
Object.defineProperty(exports, "WebhooksResource", { enumerable: true, get: function () { return account_1.WebhooksResource; } });
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RequestOptions, Transport } from "../../core/transport";
|
|
2
|
+
import { PagePromise } from "../../core/pagination";
|
|
3
|
+
import type { Model } from "../types";
|
|
4
|
+
export declare class ModelsResource {
|
|
5
|
+
private readonly transport;
|
|
6
|
+
constructor(transport: Transport);
|
|
7
|
+
/** `GET /v2/models`: every model name with its status, serving model and price. Needs no API key. */
|
|
8
|
+
list(options?: RequestOptions): PagePromise<Model>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModelsResource = void 0;
|
|
4
|
+
const pagination_1 = require("../../core/pagination");
|
|
5
|
+
class ModelsResource {
|
|
6
|
+
constructor(transport) {
|
|
7
|
+
this.transport = transport;
|
|
8
|
+
}
|
|
9
|
+
/** `GET /v2/models`: every model name with its status, serving model and price. Needs no API key. */
|
|
10
|
+
list(options) {
|
|
11
|
+
return pagination_1.PagePromise.from(async () => {
|
|
12
|
+
const response = await this.transport.request({
|
|
13
|
+
method: "GET",
|
|
14
|
+
path: "/models",
|
|
15
|
+
idempotent: true,
|
|
16
|
+
noAuth: true,
|
|
17
|
+
options
|
|
18
|
+
});
|
|
19
|
+
return new pagination_1.Page(response, async () => this.list(options));
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.ModelsResource = ModelsResource;
|