@runwayml/sdk 2.3.0 → 2.4.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/CHANGELOG.md +20 -0
- package/core.d.ts +5 -2
- package/core.d.ts.map +1 -1
- package/core.js +11 -6
- package/core.js.map +1 -1
- package/core.mjs +11 -6
- package/core.mjs.map +1 -1
- package/index.d.mts +2 -0
- package/index.d.ts +2 -0
- package/index.d.ts.map +1 -1
- package/index.js +11 -3
- package/index.js.map +1 -1
- package/index.mjs +7 -2
- package/index.mjs.map +1 -1
- package/lib/polling.d.ts +49 -0
- package/lib/polling.d.ts.map +1 -0
- package/lib/polling.js +67 -0
- package/lib/polling.js.map +1 -0
- package/lib/polling.mjs +60 -0
- package/lib/polling.mjs.map +1 -0
- package/package.json +1 -1
- package/resource.d.ts +1 -1
- package/resource.d.ts.map +1 -1
- package/resource.js.map +1 -1
- package/resource.mjs.map +1 -1
- package/resources/image-to-video.d.ts +17 -2
- package/resources/image-to-video.d.ts.map +1 -1
- package/resources/image-to-video.js +2 -1
- package/resources/image-to-video.js.map +1 -1
- package/resources/image-to-video.mjs +2 -1
- package/resources/image-to-video.mjs.map +1 -1
- package/resources/tasks.d.ts +2 -1
- package/resources/tasks.d.ts.map +1 -1
- package/resources/tasks.js +2 -1
- package/resources/tasks.js.map +1 -1
- package/resources/tasks.mjs +2 -1
- package/resources/tasks.mjs.map +1 -1
- package/resources/text-to-image.d.ts +2 -1
- package/resources/text-to-image.d.ts.map +1 -1
- package/resources/text-to-image.js +2 -1
- package/resources/text-to-image.js.map +1 -1
- package/resources/text-to-image.mjs +2 -1
- package/resources/text-to-image.mjs.map +1 -1
- package/resources/video-upscale.d.ts +2 -1
- package/resources/video-upscale.d.ts.map +1 -1
- package/resources/video-upscale.js +2 -1
- package/resources/video-upscale.js.map +1 -1
- package/resources/video-upscale.mjs +2 -1
- package/resources/video-upscale.mjs.map +1 -1
- package/src/core.ts +11 -4
- package/src/index.ts +10 -0
- package/src/lib/polling.ts +109 -0
- package/src/resource.ts +1 -1
- package/src/resources/image-to-video.ts +22 -3
- package/src/resources/tasks.ts +6 -2
- package/src/resources/text-to-image.ts +5 -2
- package/src/resources/video-upscale.ts +5 -2
- package/src/version.ts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
package/src/core.ts
CHANGED
|
@@ -170,6 +170,7 @@ export class APIPromise<T> extends Promise<T> {
|
|
|
170
170
|
|
|
171
171
|
export abstract class APIClient {
|
|
172
172
|
baseURL: string;
|
|
173
|
+
#baseURLOverridden: boolean;
|
|
173
174
|
maxRetries: number;
|
|
174
175
|
timeout: number;
|
|
175
176
|
httpAgent: Agent | undefined;
|
|
@@ -179,18 +180,21 @@ export abstract class APIClient {
|
|
|
179
180
|
|
|
180
181
|
constructor({
|
|
181
182
|
baseURL,
|
|
183
|
+
baseURLOverridden,
|
|
182
184
|
maxRetries = 2,
|
|
183
185
|
timeout = 60000, // 1 minute
|
|
184
186
|
httpAgent,
|
|
185
187
|
fetch: overriddenFetch,
|
|
186
188
|
}: {
|
|
187
189
|
baseURL: string;
|
|
190
|
+
baseURLOverridden: boolean;
|
|
188
191
|
maxRetries?: number | undefined;
|
|
189
192
|
timeout: number | undefined;
|
|
190
193
|
httpAgent: Agent | undefined;
|
|
191
194
|
fetch: Fetch | undefined;
|
|
192
195
|
}) {
|
|
193
196
|
this.baseURL = baseURL;
|
|
197
|
+
this.#baseURLOverridden = baseURLOverridden;
|
|
194
198
|
this.maxRetries = validatePositiveInteger('maxRetries', maxRetries);
|
|
195
199
|
this.timeout = validatePositiveInteger('timeout', timeout);
|
|
196
200
|
this.httpAgent = httpAgent;
|
|
@@ -300,7 +304,7 @@ export abstract class APIClient {
|
|
|
300
304
|
{ retryCount = 0 }: { retryCount?: number } = {},
|
|
301
305
|
): { req: RequestInit; url: string; timeout: number } {
|
|
302
306
|
const options = { ...inputOptions };
|
|
303
|
-
const { method, path, query, headers: headers = {} } = options;
|
|
307
|
+
const { method, path, query, defaultBaseURL, headers: headers = {} } = options;
|
|
304
308
|
|
|
305
309
|
const body =
|
|
306
310
|
ArrayBuffer.isView(options.body) || (options.__binaryRequest && typeof options.body === 'string') ?
|
|
@@ -310,7 +314,7 @@ export abstract class APIClient {
|
|
|
310
314
|
: null;
|
|
311
315
|
const contentLength = this.calculateContentLength(body);
|
|
312
316
|
|
|
313
|
-
const url = this.buildURL(path!, query);
|
|
317
|
+
const url = this.buildURL(path!, query, defaultBaseURL);
|
|
314
318
|
if ('timeout' in options) validatePositiveInteger('timeout', options.timeout);
|
|
315
319
|
options.timeout = options.timeout ?? this.timeout;
|
|
316
320
|
const httpAgent = options.httpAgent ?? this.httpAgent ?? getDefaultAgent(url);
|
|
@@ -503,11 +507,12 @@ export abstract class APIClient {
|
|
|
503
507
|
return new PagePromise<PageClass, Item>(this, request, Page);
|
|
504
508
|
}
|
|
505
509
|
|
|
506
|
-
buildURL<Req>(path: string, query: Req | null | undefined): string {
|
|
510
|
+
buildURL<Req>(path: string, query: Req | null | undefined, defaultBaseURL?: string | undefined): string {
|
|
511
|
+
const baseURL = (!this.#baseURLOverridden && defaultBaseURL) || this.baseURL;
|
|
507
512
|
const url =
|
|
508
513
|
isAbsoluteURL(path) ?
|
|
509
514
|
new URL(path)
|
|
510
|
-
: new URL(
|
|
515
|
+
: new URL(baseURL + (baseURL.endsWith('/') && path.startsWith('/') ? path.slice(1) : path));
|
|
511
516
|
|
|
512
517
|
const defaultQuery = this.defaultQuery();
|
|
513
518
|
if (!isEmptyObj(defaultQuery)) {
|
|
@@ -792,6 +797,7 @@ export type RequestOptions<
|
|
|
792
797
|
query?: Req | undefined;
|
|
793
798
|
body?: Req | null | undefined;
|
|
794
799
|
headers?: Headers | undefined;
|
|
800
|
+
defaultBaseURL?: string | undefined;
|
|
795
801
|
|
|
796
802
|
maxRetries?: number;
|
|
797
803
|
stream?: boolean | undefined;
|
|
@@ -813,6 +819,7 @@ const requestOptionsKeys: KeysEnum<RequestOptions> = {
|
|
|
813
819
|
query: true,
|
|
814
820
|
body: true,
|
|
815
821
|
headers: true,
|
|
822
|
+
defaultBaseURL: true,
|
|
816
823
|
|
|
817
824
|
maxRetries: true,
|
|
818
825
|
stream: true,
|
package/src/index.ts
CHANGED
|
@@ -133,6 +133,7 @@ export class RunwayML extends Core.APIClient {
|
|
|
133
133
|
|
|
134
134
|
super({
|
|
135
135
|
baseURL: options.baseURL!,
|
|
136
|
+
baseURLOverridden: baseURL ? baseURL !== 'https://api.dev.runwayml.com' : false,
|
|
136
137
|
timeout: options.timeout ?? 60000 /* 1 minute */,
|
|
137
138
|
httpAgent: options.httpAgent,
|
|
138
139
|
maxRetries: options.maxRetries,
|
|
@@ -151,6 +152,13 @@ export class RunwayML extends Core.APIClient {
|
|
|
151
152
|
videoUpscale: API.VideoUpscale = new API.VideoUpscale(this);
|
|
152
153
|
organization: API.Organization = new API.Organization(this);
|
|
153
154
|
|
|
155
|
+
/**
|
|
156
|
+
* Check whether the base URL is set to its default.
|
|
157
|
+
*/
|
|
158
|
+
#baseURLOverridden(): boolean {
|
|
159
|
+
return this.baseURL !== 'https://api.dev.runwayml.com';
|
|
160
|
+
}
|
|
161
|
+
|
|
154
162
|
protected override defaultQuery(): Core.DefaultQuery | undefined {
|
|
155
163
|
return this._options.defaultQuery;
|
|
156
164
|
}
|
|
@@ -236,4 +244,6 @@ export {
|
|
|
236
244
|
UnprocessableEntityError,
|
|
237
245
|
} from './error';
|
|
238
246
|
|
|
247
|
+
export { TaskFailedError, TaskTimedOutError, WaitForTaskOutputOptions, AbortError } from './lib/polling';
|
|
248
|
+
|
|
239
249
|
export default RunwayML;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { RunwayML } from '../index';
|
|
2
|
+
import * as Core from '../core';
|
|
3
|
+
import { TaskRetrieveResponse } from '../resources/tasks';
|
|
4
|
+
|
|
5
|
+
const POLL_TIME = 6000; // 6 seconds
|
|
6
|
+
const POLL_JITTER = 3000; // 3 seconds
|
|
7
|
+
|
|
8
|
+
export class TaskFailedError extends Error {
|
|
9
|
+
taskDetails: TaskRetrieveResponse;
|
|
10
|
+
constructor(taskDetails: TaskRetrieveResponse) {
|
|
11
|
+
super(taskDetails.failure!);
|
|
12
|
+
this.taskDetails = taskDetails;
|
|
13
|
+
this.name = 'TaskFailedError';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class TaskTimedOutError extends Error {
|
|
18
|
+
taskDetails: TaskRetrieveResponse;
|
|
19
|
+
constructor(taskDetails: TaskRetrieveResponse) {
|
|
20
|
+
super('Task timed out');
|
|
21
|
+
this.taskDetails = taskDetails;
|
|
22
|
+
this.name = 'TaskTimedOutError';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface WaitForTaskOutputOptions {
|
|
27
|
+
/**
|
|
28
|
+
* The maximum amount of time to wait for the task to complete in milliseconds. If not
|
|
29
|
+
* specified, the default timeout is 10 minutes. Will raise a `TaskTimeoutError` if the
|
|
30
|
+
* task does not complete within the timeout. Setting this to `null` will wait
|
|
31
|
+
* indefinitely (disabling the timeout). Disabling the timeout is not recommended.
|
|
32
|
+
* as it may cause your server to experience issues if your Runway API organization
|
|
33
|
+
* reaches its concurrency limit or if Runway experiences an outage.
|
|
34
|
+
*/
|
|
35
|
+
timeout?: number | null;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Passing an `AbortSignal` allows you to stop waiting for the task to complete.
|
|
39
|
+
* If you are using `waitForTaskOutput` in the handler for an incoming request,
|
|
40
|
+
* `waitForTaskOutput` will not stop polling if the client connection is closed.
|
|
41
|
+
* Passing an `AbortSignal` safely stops polling, preventing memory leaks and
|
|
42
|
+
* ensuring you do not create too many requests to the Runway API.
|
|
43
|
+
*/
|
|
44
|
+
abortSignal?: AbortSignal;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export class AbortError extends Error {
|
|
48
|
+
code = 22;
|
|
49
|
+
constructor() {
|
|
50
|
+
super('Polling aborted');
|
|
51
|
+
this.name = 'AbortError';
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export type APIPromiseWithAwaitableTask<T extends { id: string }> = Core.APIPromise<T> & {
|
|
56
|
+
/**
|
|
57
|
+
* When called, this will wait until the task is complete.
|
|
58
|
+
*
|
|
59
|
+
* If the task fails or is cancelled, a `TaskFailedError` will be thrown.
|
|
60
|
+
*/
|
|
61
|
+
waitForTaskOutput: (options?: WaitForTaskOutputOptions) => Promise<TaskRetrieveResponse>;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export function wrapAsWaitableResource<T extends { id: string }>(client: RunwayML) {
|
|
65
|
+
return (
|
|
66
|
+
responsePromise: Core.APIPromise<T>,
|
|
67
|
+
skipInitialWait: boolean = false,
|
|
68
|
+
): APIPromiseWithAwaitableTask<T> => {
|
|
69
|
+
return Object.defineProperty(responsePromise, 'waitForTaskOutput', {
|
|
70
|
+
value: async (options?: WaitForTaskOutputOptions) => {
|
|
71
|
+
const wait = () =>
|
|
72
|
+
new Promise<void>((resolve) =>
|
|
73
|
+
setTimeout(resolve, POLL_TIME + Math.random() * POLL_JITTER - POLL_JITTER / 2),
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
if (!skipInitialWait) {
|
|
77
|
+
await wait();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const { timeout = 60 * 10 * 1000 } = options ?? {};
|
|
81
|
+
const output = await responsePromise;
|
|
82
|
+
const startTime = Date.now();
|
|
83
|
+
let taskDetails: TaskRetrieveResponse;
|
|
84
|
+
do {
|
|
85
|
+
if (options?.abortSignal?.aborted) {
|
|
86
|
+
throw new AbortError();
|
|
87
|
+
}
|
|
88
|
+
taskDetails = await client.tasks.retrieve(output.id);
|
|
89
|
+
if (taskDetails.status === 'SUCCEEDED') {
|
|
90
|
+
return taskDetails;
|
|
91
|
+
}
|
|
92
|
+
if (taskDetails.status === 'FAILED' || taskDetails.status === 'CANCELLED') {
|
|
93
|
+
throw new TaskFailedError(taskDetails);
|
|
94
|
+
}
|
|
95
|
+
await wait();
|
|
96
|
+
if (timeout != null && Date.now() - startTime > timeout && !options?.abortSignal?.aborted) {
|
|
97
|
+
throw new TaskTimedOutError(taskDetails);
|
|
98
|
+
}
|
|
99
|
+
} while (['THROTTLED', 'PENDING', 'RUNNING'].includes(taskDetails.status));
|
|
100
|
+
throw new TaskTimedOutError(taskDetails);
|
|
101
|
+
},
|
|
102
|
+
writable: false,
|
|
103
|
+
enumerable: false,
|
|
104
|
+
configurable: false,
|
|
105
|
+
}) as Core.APIPromise<T> & {
|
|
106
|
+
waitForTaskOutput: () => Promise<TaskRetrieveResponse>;
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
}
|
package/src/resource.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { APIResource } from '../resource';
|
|
4
4
|
import * as Core from '../core';
|
|
5
|
+
import { APIPromiseWithAwaitableTask, wrapAsWaitableResource } from '../lib/polling';
|
|
5
6
|
|
|
6
7
|
export class ImageToVideo extends APIResource {
|
|
7
8
|
/**
|
|
@@ -10,8 +11,10 @@ export class ImageToVideo extends APIResource {
|
|
|
10
11
|
create(
|
|
11
12
|
body: ImageToVideoCreateParams,
|
|
12
13
|
options?: Core.RequestOptions,
|
|
13
|
-
):
|
|
14
|
-
return this._client
|
|
14
|
+
): APIPromiseWithAwaitableTask<ImageToVideoCreateResponse> {
|
|
15
|
+
return wrapAsWaitableResource<ImageToVideoCreateResponse>(this._client)(
|
|
16
|
+
this._client.post('/v1/image_to_video', { body, ...options }),
|
|
17
|
+
);
|
|
15
18
|
}
|
|
16
19
|
}
|
|
17
20
|
|
|
@@ -27,7 +30,7 @@ export interface ImageToVideoCreateParams {
|
|
|
27
30
|
/**
|
|
28
31
|
* The model variant to use.
|
|
29
32
|
*/
|
|
30
|
-
model: '
|
|
33
|
+
model: 'gen3a_turbo' | 'gen4_turbo';
|
|
31
34
|
|
|
32
35
|
/**
|
|
33
36
|
* A HTTPS URL or data URI containing an encoded image to be used as the first
|
|
@@ -55,6 +58,11 @@ export interface ImageToVideoCreateParams {
|
|
|
55
58
|
*/
|
|
56
59
|
ratio: '1280:720' | '720:1280' | '1104:832' | '832:1104' | '960:960' | '1584:672' | '1280:768' | '768:1280';
|
|
57
60
|
|
|
61
|
+
/**
|
|
62
|
+
* Settings that affect the behavior of the content moderation system.
|
|
63
|
+
*/
|
|
64
|
+
contentModeration?: ImageToVideoCreateParams.ContentModeration;
|
|
65
|
+
|
|
58
66
|
/**
|
|
59
67
|
* The number of seconds of duration for the output video.
|
|
60
68
|
*/
|
|
@@ -91,6 +99,17 @@ export namespace ImageToVideoCreateParams {
|
|
|
91
99
|
*/
|
|
92
100
|
uri: string;
|
|
93
101
|
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Settings that affect the behavior of the content moderation system.
|
|
105
|
+
*/
|
|
106
|
+
export interface ContentModeration {
|
|
107
|
+
/**
|
|
108
|
+
* When set to `low`, the content moderation system will be less strict about
|
|
109
|
+
* preventing generations that include recognizable public figures.
|
|
110
|
+
*/
|
|
111
|
+
publicFigureThreshold?: 'auto' | 'low';
|
|
112
|
+
}
|
|
94
113
|
}
|
|
95
114
|
|
|
96
115
|
export declare namespace ImageToVideo {
|
package/src/resources/tasks.ts
CHANGED
|
@@ -2,14 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
import { APIResource } from '../resource';
|
|
4
4
|
import * as Core from '../core';
|
|
5
|
+
import { APIPromiseWithAwaitableTask, wrapAsWaitableResource } from '../lib/polling';
|
|
5
6
|
|
|
6
7
|
export class Tasks extends APIResource {
|
|
7
8
|
/**
|
|
8
9
|
* Return details about a task. Consumers of this API should not expect updates
|
|
9
10
|
* more frequent than once every five seconds for a given task.
|
|
10
11
|
*/
|
|
11
|
-
retrieve(id: string, options?: Core.RequestOptions):
|
|
12
|
-
return this._client
|
|
12
|
+
retrieve(id: string, options?: Core.RequestOptions): APIPromiseWithAwaitableTask<TaskRetrieveResponse> {
|
|
13
|
+
return wrapAsWaitableResource<TaskRetrieveResponse>(this._client)(
|
|
14
|
+
this._client.get(`/v1/tasks/${id}`, options),
|
|
15
|
+
true,
|
|
16
|
+
);
|
|
13
17
|
}
|
|
14
18
|
|
|
15
19
|
/**
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { APIResource } from '../resource';
|
|
4
4
|
import * as Core from '../core';
|
|
5
|
+
import { APIPromiseWithAwaitableTask, wrapAsWaitableResource } from '../lib/polling';
|
|
5
6
|
|
|
6
7
|
export class TextToImage extends APIResource {
|
|
7
8
|
/**
|
|
@@ -10,8 +11,10 @@ export class TextToImage extends APIResource {
|
|
|
10
11
|
create(
|
|
11
12
|
body: TextToImageCreateParams,
|
|
12
13
|
options?: Core.RequestOptions,
|
|
13
|
-
):
|
|
14
|
-
return this._client
|
|
14
|
+
): APIPromiseWithAwaitableTask<TextToImageCreateResponse> {
|
|
15
|
+
return wrapAsWaitableResource<TextToImageCreateResponse>(this._client)(
|
|
16
|
+
this._client.post('/v1/text_to_image', { body, ...options }),
|
|
17
|
+
);
|
|
15
18
|
}
|
|
16
19
|
}
|
|
17
20
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { APIResource } from '../resource';
|
|
4
4
|
import * as Core from '../core';
|
|
5
|
+
import { APIPromiseWithAwaitableTask, wrapAsWaitableResource } from '../lib/polling';
|
|
5
6
|
|
|
6
7
|
export class VideoUpscale extends APIResource {
|
|
7
8
|
/**
|
|
@@ -11,8 +12,10 @@ export class VideoUpscale extends APIResource {
|
|
|
11
12
|
create(
|
|
12
13
|
body: VideoUpscaleCreateParams,
|
|
13
14
|
options?: Core.RequestOptions,
|
|
14
|
-
):
|
|
15
|
-
return this._client
|
|
15
|
+
): APIPromiseWithAwaitableTask<VideoUpscaleCreateResponse> {
|
|
16
|
+
return wrapAsWaitableResource<VideoUpscaleCreateResponse>(this._client)(
|
|
17
|
+
this._client.post('/v1/video_upscale', { body, ...options }),
|
|
18
|
+
);
|
|
16
19
|
}
|
|
17
20
|
}
|
|
18
21
|
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '2.
|
|
1
|
+
export const VERSION = '2.4.0'; // x-release-please-version
|
package/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "2.
|
|
1
|
+
export declare const VERSION = "2.4.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/version.js
CHANGED
package/version.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '2.
|
|
1
|
+
export const VERSION = '2.4.0'; // x-release-please-version
|
|
2
2
|
//# sourceMappingURL=version.mjs.map
|