@runwayml/sdk 3.11.0 → 3.15.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 +115 -0
- package/LICENSE +1 -1
- package/README.md +43 -2
- package/client.d.mts +53 -4
- package/client.d.mts.map +1 -1
- package/client.d.ts +53 -4
- package/client.d.ts.map +1 -1
- package/client.js +75 -20
- package/client.js.map +1 -1
- package/client.mjs +75 -20
- package/client.mjs.map +1 -1
- package/core/pagination.d.mts +54 -0
- package/core/pagination.d.mts.map +1 -0
- package/core/pagination.d.ts +54 -0
- package/core/pagination.d.ts.map +1 -0
- package/core/pagination.js +101 -0
- package/core/pagination.js.map +1 -0
- package/core/pagination.mjs +95 -0
- package/core/pagination.mjs.map +1 -0
- package/index.d.mts +1 -0
- package/index.d.mts.map +1 -1
- package/index.d.ts +1 -0
- package/index.d.ts.map +1 -1
- package/index.js +3 -1
- package/index.js.map +1 -1
- package/index.mjs +1 -0
- package/index.mjs.map +1 -1
- package/internal/parse.d.mts.map +1 -1
- package/internal/parse.d.ts.map +1 -1
- package/internal/parse.js +5 -0
- package/internal/parse.js.map +1 -1
- package/internal/parse.mjs +5 -0
- package/internal/parse.mjs.map +1 -1
- package/internal/tslib.js +17 -17
- package/internal/utils/query.d.mts +5 -0
- package/internal/utils/query.d.mts.map +1 -0
- package/internal/utils/query.d.ts +5 -0
- package/internal/utils/query.d.ts.map +1 -0
- package/internal/utils/query.js +23 -0
- package/internal/utils/query.js.map +1 -0
- package/internal/utils/query.mjs +20 -0
- package/internal/utils/query.mjs.map +1 -0
- package/internal/utils.d.mts +1 -0
- package/internal/utils.d.ts +1 -0
- package/internal/utils.js +1 -0
- package/internal/utils.js.map +1 -1
- package/internal/utils.mjs +1 -0
- package/package.json +11 -1
- package/pagination.d.mts +2 -0
- package/pagination.d.mts.map +1 -0
- package/pagination.d.ts +2 -0
- package/pagination.d.ts.map +1 -0
- package/pagination.js +6 -0
- package/pagination.js.map +1 -0
- package/pagination.mjs +2 -0
- package/pagination.mjs.map +1 -0
- package/resources/avatars.d.mts +1308 -0
- package/resources/avatars.d.mts.map +1 -0
- package/resources/avatars.d.ts +1308 -0
- package/resources/avatars.d.ts.map +1 -0
- package/resources/avatars.js +87 -0
- package/resources/avatars.js.map +1 -0
- package/resources/avatars.mjs +83 -0
- package/resources/avatars.mjs.map +1 -0
- package/resources/character-performance.d.mts +3 -0
- package/resources/character-performance.d.mts.map +1 -1
- package/resources/character-performance.d.ts +3 -0
- package/resources/character-performance.d.ts.map +1 -1
- package/resources/character-performance.js +3 -0
- package/resources/character-performance.js.map +1 -1
- package/resources/character-performance.mjs +3 -0
- package/resources/character-performance.mjs.map +1 -1
- package/resources/documents.d.mts +209 -0
- package/resources/documents.d.mts.map +1 -0
- package/resources/documents.d.ts +209 -0
- package/resources/documents.d.ts.map +1 -0
- package/resources/documents.js +75 -0
- package/resources/documents.js.map +1 -0
- package/resources/documents.mjs +71 -0
- package/resources/documents.mjs.map +1 -0
- package/resources/image-to-video.d.mts +58 -1
- package/resources/image-to-video.d.mts.map +1 -1
- package/resources/image-to-video.d.ts +58 -1
- package/resources/image-to-video.d.ts.map +1 -1
- package/resources/image-to-video.js +3 -0
- package/resources/image-to-video.js.map +1 -1
- package/resources/image-to-video.mjs +3 -0
- package/resources/image-to-video.mjs.map +1 -1
- package/resources/index.d.mts +4 -1
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +4 -1
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js +9 -3
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +4 -1
- package/resources/index.mjs.map +1 -1
- package/resources/organization.d.mts +2 -2
- package/resources/organization.d.mts.map +1 -1
- package/resources/organization.d.ts +2 -2
- package/resources/organization.d.ts.map +1 -1
- package/resources/realtime-sessions.d.mts +180 -0
- package/resources/realtime-sessions.d.mts.map +1 -0
- package/resources/realtime-sessions.d.ts +180 -0
- package/resources/realtime-sessions.d.ts.map +1 -0
- package/resources/realtime-sessions.js +32 -0
- package/resources/realtime-sessions.js.map +1 -0
- package/resources/realtime-sessions.mjs +28 -0
- package/resources/realtime-sessions.mjs.map +1 -0
- package/resources/sound-effect.d.mts +3 -0
- package/resources/sound-effect.d.mts.map +1 -1
- package/resources/sound-effect.d.ts +3 -0
- package/resources/sound-effect.d.ts.map +1 -1
- package/resources/sound-effect.js +3 -0
- package/resources/sound-effect.js.map +1 -1
- package/resources/sound-effect.mjs +3 -0
- package/resources/sound-effect.mjs.map +1 -1
- package/resources/speech-to-speech.d.mts +3 -0
- package/resources/speech-to-speech.d.mts.map +1 -1
- package/resources/speech-to-speech.d.ts +3 -0
- package/resources/speech-to-speech.d.ts.map +1 -1
- package/resources/speech-to-speech.js +3 -0
- package/resources/speech-to-speech.js.map +1 -1
- package/resources/speech-to-speech.mjs +3 -0
- package/resources/speech-to-speech.mjs.map +1 -1
- package/resources/tasks.d.mts +3 -0
- package/resources/tasks.d.mts.map +1 -1
- package/resources/tasks.d.ts +3 -0
- package/resources/tasks.d.ts.map +1 -1
- package/resources/tasks.js +3 -0
- package/resources/tasks.js.map +1 -1
- package/resources/tasks.mjs +3 -0
- package/resources/tasks.mjs.map +1 -1
- package/resources/text-to-image.d.mts +3 -0
- package/resources/text-to-image.d.mts.map +1 -1
- package/resources/text-to-image.d.ts +3 -0
- package/resources/text-to-image.d.ts.map +1 -1
- package/resources/text-to-image.js +3 -0
- package/resources/text-to-image.js.map +1 -1
- package/resources/text-to-image.mjs +3 -0
- package/resources/text-to-image.mjs.map +1 -1
- package/resources/text-to-speech.d.mts +3 -0
- package/resources/text-to-speech.d.mts.map +1 -1
- package/resources/text-to-speech.d.ts +3 -0
- package/resources/text-to-speech.d.ts.map +1 -1
- package/resources/text-to-speech.js +3 -0
- package/resources/text-to-speech.js.map +1 -1
- package/resources/text-to-speech.mjs +3 -0
- package/resources/text-to-speech.mjs.map +1 -1
- package/resources/text-to-video.d.mts +43 -1
- package/resources/text-to-video.d.mts.map +1 -1
- package/resources/text-to-video.d.ts +43 -1
- package/resources/text-to-video.d.ts.map +1 -1
- package/resources/text-to-video.js +3 -0
- package/resources/text-to-video.js.map +1 -1
- package/resources/text-to-video.mjs +3 -0
- package/resources/text-to-video.mjs.map +1 -1
- package/resources/video-to-video.d.mts +8 -5
- package/resources/video-to-video.d.mts.map +1 -1
- package/resources/video-to-video.d.ts +8 -5
- package/resources/video-to-video.d.ts.map +1 -1
- package/resources/video-to-video.js +3 -1
- package/resources/video-to-video.js.map +1 -1
- package/resources/video-to-video.mjs +3 -1
- package/resources/video-to-video.mjs.map +1 -1
- package/resources/voice-dubbing.d.mts +3 -0
- package/resources/voice-dubbing.d.mts.map +1 -1
- package/resources/voice-dubbing.d.ts +3 -0
- package/resources/voice-dubbing.d.ts.map +1 -1
- package/resources/voice-dubbing.js +3 -0
- package/resources/voice-dubbing.js.map +1 -1
- package/resources/voice-dubbing.mjs +3 -0
- package/resources/voice-dubbing.mjs.map +1 -1
- package/resources/voice-isolation.d.mts +3 -0
- package/resources/voice-isolation.d.mts.map +1 -1
- package/resources/voice-isolation.d.ts +3 -0
- package/resources/voice-isolation.d.ts.map +1 -1
- package/resources/voice-isolation.js +3 -0
- package/resources/voice-isolation.js.map +1 -1
- package/resources/voice-isolation.mjs +3 -0
- package/resources/voice-isolation.mjs.map +1 -1
- package/resources/voices.d.mts +257 -0
- package/resources/voices.d.mts.map +1 -0
- package/resources/voices.d.ts +257 -0
- package/resources/voices.d.ts.map +1 -0
- package/resources/voices.js +47 -0
- package/resources/voices.js.map +1 -0
- package/resources/voices.mjs +43 -0
- package/resources/voices.mjs.map +1 -0
- package/src/client.ts +173 -35
- package/src/core/pagination.ts +157 -0
- package/src/index.ts +1 -0
- package/src/internal/parse.ts +6 -0
- package/src/internal/utils/query.ts +23 -0
- package/src/internal/utils.ts +1 -0
- package/src/pagination.ts +2 -0
- package/src/resources/avatars.ts +2049 -0
- package/src/resources/character-performance.ts +3 -0
- package/src/resources/documents.ts +270 -0
- package/src/resources/image-to-video.ts +68 -0
- package/src/resources/index.ts +37 -5
- package/src/resources/organization.ts +7 -3
- package/src/resources/realtime-sessions.ts +251 -0
- package/src/resources/sound-effect.ts +3 -0
- package/src/resources/speech-to-speech.ts +3 -0
- package/src/resources/tasks.ts +3 -0
- package/src/resources/text-to-image.ts +3 -0
- package/src/resources/text-to-speech.ts +3 -0
- package/src/resources/text-to-video.ts +50 -0
- package/src/resources/video-to-video.ts +9 -6
- package/src/resources/voice-dubbing.ts +3 -0
- package/src/resources/voice-isolation.ts +3 -0
- package/src/resources/voices.ts +345 -0
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
- package/resources/video-upscale.d.mts +0 -35
- package/resources/video-upscale.d.mts.map +0 -1
- package/resources/video-upscale.d.ts +0 -35
- package/resources/video-upscale.d.ts.map +0 -1
- package/resources/video-upscale.js +0 -25
- package/resources/video-upscale.js.map +0 -1
- package/resources/video-upscale.mjs +0 -21
- package/resources/video-upscale.mjs.map +0 -1
- package/src/resources/video-upscale.ts +0 -51
package/src/client.ts
CHANGED
|
@@ -11,16 +11,39 @@ import type { APIResponseProps } from './internal/parse';
|
|
|
11
11
|
import { getPlatformHeaders } from './internal/detect-platform';
|
|
12
12
|
import * as Shims from './internal/shims';
|
|
13
13
|
import * as Opts from './internal/request-options';
|
|
14
|
+
import { stringifyQuery } from './internal/utils/query';
|
|
14
15
|
import { VERSION } from './version';
|
|
15
16
|
import * as Errors from './core/error';
|
|
17
|
+
import * as Pagination from './core/pagination';
|
|
18
|
+
import { AbstractPage, type CursorPageParams, CursorPageResponse } from './core/pagination';
|
|
16
19
|
import * as UploadsCore from './core/uploads';
|
|
17
20
|
import * as API from './resources/index';
|
|
18
21
|
import { APIPromise } from './core/api-promise';
|
|
22
|
+
import {
|
|
23
|
+
AvatarCreateParams,
|
|
24
|
+
AvatarCreateResponse,
|
|
25
|
+
AvatarListParams,
|
|
26
|
+
AvatarListResponse,
|
|
27
|
+
AvatarListResponsesCursorPage,
|
|
28
|
+
AvatarRetrieveResponse,
|
|
29
|
+
AvatarUpdateParams,
|
|
30
|
+
AvatarUpdateResponse,
|
|
31
|
+
Avatars,
|
|
32
|
+
} from './resources/avatars';
|
|
19
33
|
import {
|
|
20
34
|
CharacterPerformance,
|
|
21
35
|
CharacterPerformanceCreateParams,
|
|
22
36
|
CharacterPerformanceCreateResponse,
|
|
23
37
|
} from './resources/character-performance';
|
|
38
|
+
import {
|
|
39
|
+
DocumentCreateParams,
|
|
40
|
+
DocumentCreateResponse,
|
|
41
|
+
DocumentListParams,
|
|
42
|
+
DocumentListResponse,
|
|
43
|
+
DocumentListResponsesCursorPage,
|
|
44
|
+
DocumentRetrieveResponse,
|
|
45
|
+
Documents,
|
|
46
|
+
} from './resources/documents';
|
|
24
47
|
import {
|
|
25
48
|
ImageToVideo,
|
|
26
49
|
ImageToVideoCreateParams,
|
|
@@ -32,6 +55,12 @@ import {
|
|
|
32
55
|
OrganizationRetrieveUsageParams,
|
|
33
56
|
OrganizationRetrieveUsageResponse,
|
|
34
57
|
} from './resources/organization';
|
|
58
|
+
import {
|
|
59
|
+
RealtimeSessionCreateParams,
|
|
60
|
+
RealtimeSessionCreateResponse,
|
|
61
|
+
RealtimeSessionRetrieveResponse,
|
|
62
|
+
RealtimeSessions,
|
|
63
|
+
} from './resources/realtime-sessions';
|
|
35
64
|
import { SoundEffect, SoundEffectCreateParams, SoundEffectCreateResponse } from './resources/sound-effect';
|
|
36
65
|
import {
|
|
37
66
|
SpeechToSpeech,
|
|
@@ -51,11 +80,6 @@ import {
|
|
|
51
80
|
VideoToVideoCreateParams,
|
|
52
81
|
VideoToVideoCreateResponse,
|
|
53
82
|
} from './resources/video-to-video';
|
|
54
|
-
import {
|
|
55
|
-
VideoUpscale,
|
|
56
|
-
VideoUpscaleCreateParams,
|
|
57
|
-
VideoUpscaleCreateResponse,
|
|
58
|
-
} from './resources/video-upscale';
|
|
59
83
|
import {
|
|
60
84
|
VoiceDubbing,
|
|
61
85
|
VoiceDubbingCreateParams,
|
|
@@ -67,6 +91,17 @@ import {
|
|
|
67
91
|
VoiceIsolationCreateResponse,
|
|
68
92
|
} from './resources/voice-isolation';
|
|
69
93
|
import { Uploads, UploadsCreateEphemeralParams, UploadCreateEphemeralResponse } from './resources/uploads';
|
|
94
|
+
import {
|
|
95
|
+
VoiceCreateParams,
|
|
96
|
+
VoiceCreateResponse,
|
|
97
|
+
VoiceListParams,
|
|
98
|
+
VoiceListResponse,
|
|
99
|
+
VoiceListResponsesCursorPage,
|
|
100
|
+
VoicePreviewParams,
|
|
101
|
+
VoicePreviewResponse,
|
|
102
|
+
VoiceRetrieveResponse,
|
|
103
|
+
Voices,
|
|
104
|
+
} from './resources/voices';
|
|
70
105
|
import { type Fetch } from './internal/builtin-types';
|
|
71
106
|
import { isRunningInBrowser } from './internal/detect-platform';
|
|
72
107
|
import { HeadersLike, NullableHeaders, buildHeaders } from './internal/headers';
|
|
@@ -278,21 +313,8 @@ export class RunwayML {
|
|
|
278
313
|
/**
|
|
279
314
|
* Basic re-implementation of `qs.stringify` for primitive types.
|
|
280
315
|
*/
|
|
281
|
-
protected stringifyQuery(query: Record<string, unknown>): string {
|
|
282
|
-
return
|
|
283
|
-
.filter(([_, value]) => typeof value !== 'undefined')
|
|
284
|
-
.map(([key, value]) => {
|
|
285
|
-
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
|
286
|
-
return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
|
287
|
-
}
|
|
288
|
-
if (value === null) {
|
|
289
|
-
return `${encodeURIComponent(key)}=`;
|
|
290
|
-
}
|
|
291
|
-
throw new Errors.RunwayMLError(
|
|
292
|
-
`Cannot stringify type ${typeof value}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`,
|
|
293
|
-
);
|
|
294
|
-
})
|
|
295
|
-
.join('&');
|
|
316
|
+
protected stringifyQuery(query: object | Record<string, unknown>): string {
|
|
317
|
+
return stringifyQuery(query);
|
|
296
318
|
}
|
|
297
319
|
|
|
298
320
|
private getUserAgent(): string {
|
|
@@ -329,7 +351,7 @@ export class RunwayML {
|
|
|
329
351
|
}
|
|
330
352
|
|
|
331
353
|
if (typeof query === 'object' && query && !Array.isArray(query)) {
|
|
332
|
-
url.search = this.stringifyQuery(query
|
|
354
|
+
url.search = this.stringifyQuery(query);
|
|
333
355
|
}
|
|
334
356
|
|
|
335
357
|
return url.toString();
|
|
@@ -513,7 +535,7 @@ export class RunwayML {
|
|
|
513
535
|
loggerFor(this).info(`${responseInfo} - ${retryMessage}`);
|
|
514
536
|
|
|
515
537
|
const errText = await response.text().catch((err: any) => castToError(err).message);
|
|
516
|
-
const errJSON = safeJSON(errText);
|
|
538
|
+
const errJSON = safeJSON(errText) as any;
|
|
517
539
|
const errMessage = errJSON ? undefined : errText;
|
|
518
540
|
|
|
519
541
|
loggerFor(this).debug(
|
|
@@ -547,6 +569,30 @@ export class RunwayML {
|
|
|
547
569
|
return { response, options, controller, requestLogID, retryOfRequestLogID, startTime };
|
|
548
570
|
}
|
|
549
571
|
|
|
572
|
+
getAPIList<Item, PageClass extends Pagination.AbstractPage<Item> = Pagination.AbstractPage<Item>>(
|
|
573
|
+
path: string,
|
|
574
|
+
Page: new (...args: any[]) => PageClass,
|
|
575
|
+
opts?: PromiseOrValue<RequestOptions>,
|
|
576
|
+
): Pagination.PagePromise<PageClass, Item> {
|
|
577
|
+
return this.requestAPIList(
|
|
578
|
+
Page,
|
|
579
|
+
opts && 'then' in opts ?
|
|
580
|
+
opts.then((opts) => ({ method: 'get', path, ...opts }))
|
|
581
|
+
: { method: 'get', path, ...opts },
|
|
582
|
+
);
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
requestAPIList<
|
|
586
|
+
Item = unknown,
|
|
587
|
+
PageClass extends Pagination.AbstractPage<Item> = Pagination.AbstractPage<Item>,
|
|
588
|
+
>(
|
|
589
|
+
Page: new (...args: ConstructorParameters<typeof Pagination.AbstractPage>) => PageClass,
|
|
590
|
+
options: PromiseOrValue<FinalRequestOptions>,
|
|
591
|
+
): Pagination.PagePromise<PageClass, Item> {
|
|
592
|
+
const request = this.makeRequest(options, null, undefined);
|
|
593
|
+
return new Pagination.PagePromise<PageClass, Item>(this as any as RunwayML, request, Page);
|
|
594
|
+
}
|
|
595
|
+
|
|
550
596
|
async fetchWithTimeout(
|
|
551
597
|
url: RequestInfo,
|
|
552
598
|
init: RequestInit | undefined,
|
|
@@ -554,9 +600,10 @@ export class RunwayML {
|
|
|
554
600
|
controller: AbortController,
|
|
555
601
|
): Promise<Response> {
|
|
556
602
|
const { signal, method, ...options } = init || {};
|
|
557
|
-
|
|
603
|
+
const abort = this._makeAbort(controller);
|
|
604
|
+
if (signal) signal.addEventListener('abort', abort, { once: true });
|
|
558
605
|
|
|
559
|
-
const timeout = setTimeout(
|
|
606
|
+
const timeout = setTimeout(abort, ms);
|
|
560
607
|
|
|
561
608
|
const isReadableBody =
|
|
562
609
|
((globalThis as any).ReadableStream && options.body instanceof (globalThis as any).ReadableStream) ||
|
|
@@ -633,9 +680,9 @@ export class RunwayML {
|
|
|
633
680
|
}
|
|
634
681
|
}
|
|
635
682
|
|
|
636
|
-
// If the API asks us to wait a certain amount of time
|
|
637
|
-
//
|
|
638
|
-
if (
|
|
683
|
+
// If the API asks us to wait a certain amount of time, just do what it
|
|
684
|
+
// says, but otherwise calculate a default
|
|
685
|
+
if (timeoutMillis === undefined) {
|
|
639
686
|
const maxRetries = options.maxRetries ?? this.maxRetries;
|
|
640
687
|
timeoutMillis = this.calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries);
|
|
641
688
|
}
|
|
@@ -724,6 +771,12 @@ export class RunwayML {
|
|
|
724
771
|
return headers.values;
|
|
725
772
|
}
|
|
726
773
|
|
|
774
|
+
private _makeAbort(controller: AbortController) {
|
|
775
|
+
// note: we can't just inline this method inside `fetchWithTimeout()` because then the closure
|
|
776
|
+
// would capture all request options, and cause a memory leak.
|
|
777
|
+
return () => controller.abort();
|
|
778
|
+
}
|
|
779
|
+
|
|
727
780
|
private buildBody({ options: { body, headers: rawHeaders } }: { options: FinalRequestOptions }): {
|
|
728
781
|
bodyHeaders: HeadersLike;
|
|
729
782
|
body: BodyInit | undefined;
|
|
@@ -756,6 +809,14 @@ export class RunwayML {
|
|
|
756
809
|
(Symbol.iterator in body && 'next' in body && typeof body.next === 'function'))
|
|
757
810
|
) {
|
|
758
811
|
return { bodyHeaders: undefined, body: Shims.ReadableStreamFrom(body as AsyncIterable<Uint8Array>) };
|
|
812
|
+
} else if (
|
|
813
|
+
typeof body === 'object' &&
|
|
814
|
+
headers.values.get('content-type') === 'application/x-www-form-urlencoded'
|
|
815
|
+
) {
|
|
816
|
+
return {
|
|
817
|
+
bodyHeaders: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
818
|
+
body: this.stringifyQuery(body),
|
|
819
|
+
};
|
|
759
820
|
} else {
|
|
760
821
|
return this.#encoder({ body, headers });
|
|
761
822
|
}
|
|
@@ -780,19 +841,55 @@ export class RunwayML {
|
|
|
780
841
|
|
|
781
842
|
static toFile = UploadsCore.toFile;
|
|
782
843
|
|
|
844
|
+
/**
|
|
845
|
+
* Endpoints for managing tasks that have been submitted.
|
|
846
|
+
*/
|
|
783
847
|
tasks: API.Tasks = new API.Tasks(this);
|
|
848
|
+
/**
|
|
849
|
+
* These endpoints all kick off tasks to create generations.
|
|
850
|
+
*/
|
|
784
851
|
imageToVideo: API.ImageToVideo = new API.ImageToVideo(this);
|
|
852
|
+
/**
|
|
853
|
+
* These endpoints all kick off tasks to create generations.
|
|
854
|
+
*/
|
|
785
855
|
videoToVideo: API.VideoToVideo = new API.VideoToVideo(this);
|
|
856
|
+
/**
|
|
857
|
+
* These endpoints all kick off tasks to create generations.
|
|
858
|
+
*/
|
|
786
859
|
textToVideo: API.TextToVideo = new API.TextToVideo(this);
|
|
860
|
+
/**
|
|
861
|
+
* These endpoints all kick off tasks to create generations.
|
|
862
|
+
*/
|
|
787
863
|
textToImage: API.TextToImage = new API.TextToImage(this);
|
|
788
|
-
|
|
864
|
+
/**
|
|
865
|
+
* These endpoints all kick off tasks to create generations.
|
|
866
|
+
*/
|
|
789
867
|
characterPerformance: API.CharacterPerformance = new API.CharacterPerformance(this);
|
|
868
|
+
/**
|
|
869
|
+
* These endpoints all kick off tasks to create generations.
|
|
870
|
+
*/
|
|
790
871
|
textToSpeech: API.TextToSpeech = new API.TextToSpeech(this);
|
|
872
|
+
/**
|
|
873
|
+
* These endpoints all kick off tasks to create generations.
|
|
874
|
+
*/
|
|
791
875
|
soundEffect: API.SoundEffect = new API.SoundEffect(this);
|
|
876
|
+
/**
|
|
877
|
+
* These endpoints all kick off tasks to create generations.
|
|
878
|
+
*/
|
|
792
879
|
voiceIsolation: API.VoiceIsolation = new API.VoiceIsolation(this);
|
|
880
|
+
/**
|
|
881
|
+
* These endpoints all kick off tasks to create generations.
|
|
882
|
+
*/
|
|
793
883
|
voiceDubbing: API.VoiceDubbing = new API.VoiceDubbing(this);
|
|
884
|
+
/**
|
|
885
|
+
* These endpoints all kick off tasks to create generations.
|
|
886
|
+
*/
|
|
794
887
|
speechToSpeech: API.SpeechToSpeech = new API.SpeechToSpeech(this);
|
|
795
888
|
organization: API.Organization = new API.Organization(this);
|
|
889
|
+
avatars: API.Avatars = new API.Avatars(this);
|
|
890
|
+
documents: API.Documents = new API.Documents(this);
|
|
891
|
+
realtimeSessions: API.RealtimeSessions = new API.RealtimeSessions(this);
|
|
892
|
+
voices: API.Voices = new API.Voices(this);
|
|
796
893
|
uploads: API.Uploads = new API.Uploads(this);
|
|
797
894
|
}
|
|
798
895
|
|
|
@@ -801,7 +898,6 @@ RunwayML.ImageToVideo = ImageToVideo;
|
|
|
801
898
|
RunwayML.VideoToVideo = VideoToVideo;
|
|
802
899
|
RunwayML.TextToVideo = TextToVideo;
|
|
803
900
|
RunwayML.TextToImage = TextToImage;
|
|
804
|
-
RunwayML.VideoUpscale = VideoUpscale;
|
|
805
901
|
RunwayML.CharacterPerformance = CharacterPerformance;
|
|
806
902
|
RunwayML.TextToSpeech = TextToSpeech;
|
|
807
903
|
RunwayML.SoundEffect = SoundEffect;
|
|
@@ -809,11 +905,18 @@ RunwayML.VoiceIsolation = VoiceIsolation;
|
|
|
809
905
|
RunwayML.VoiceDubbing = VoiceDubbing;
|
|
810
906
|
RunwayML.SpeechToSpeech = SpeechToSpeech;
|
|
811
907
|
RunwayML.Organization = Organization;
|
|
908
|
+
RunwayML.Avatars = Avatars;
|
|
909
|
+
RunwayML.Documents = Documents;
|
|
910
|
+
RunwayML.RealtimeSessions = RealtimeSessions;
|
|
911
|
+
RunwayML.Voices = Voices;
|
|
812
912
|
RunwayML.Uploads = Uploads;
|
|
813
913
|
|
|
814
914
|
export declare namespace RunwayML {
|
|
815
915
|
export type RequestOptions = Opts.RequestOptions;
|
|
816
916
|
|
|
917
|
+
export import CursorPage = Pagination.CursorPage;
|
|
918
|
+
export { type CursorPageParams as CursorPageParams, type CursorPageResponse as CursorPageResponse };
|
|
919
|
+
|
|
817
920
|
export { Tasks as Tasks, type TaskRetrieveResponse as TaskRetrieveResponse };
|
|
818
921
|
|
|
819
922
|
export {
|
|
@@ -840,12 +943,6 @@ export declare namespace RunwayML {
|
|
|
840
943
|
type TextToImageCreateParams as TextToImageCreateParams,
|
|
841
944
|
};
|
|
842
945
|
|
|
843
|
-
export {
|
|
844
|
-
VideoUpscale as VideoUpscale,
|
|
845
|
-
type VideoUpscaleCreateResponse as VideoUpscaleCreateResponse,
|
|
846
|
-
type VideoUpscaleCreateParams as VideoUpscaleCreateParams,
|
|
847
|
-
};
|
|
848
|
-
|
|
849
946
|
export {
|
|
850
947
|
CharacterPerformance as CharacterPerformance,
|
|
851
948
|
type CharacterPerformanceCreateResponse as CharacterPerformanceCreateResponse,
|
|
@@ -889,6 +986,47 @@ export declare namespace RunwayML {
|
|
|
889
986
|
type OrganizationRetrieveUsageParams as OrganizationRetrieveUsageParams,
|
|
890
987
|
};
|
|
891
988
|
|
|
989
|
+
export {
|
|
990
|
+
Avatars as Avatars,
|
|
991
|
+
type AvatarCreateResponse as AvatarCreateResponse,
|
|
992
|
+
type AvatarRetrieveResponse as AvatarRetrieveResponse,
|
|
993
|
+
type AvatarUpdateResponse as AvatarUpdateResponse,
|
|
994
|
+
type AvatarListResponse as AvatarListResponse,
|
|
995
|
+
type AvatarListResponsesCursorPage as AvatarListResponsesCursorPage,
|
|
996
|
+
type AvatarCreateParams as AvatarCreateParams,
|
|
997
|
+
type AvatarUpdateParams as AvatarUpdateParams,
|
|
998
|
+
type AvatarListParams as AvatarListParams,
|
|
999
|
+
};
|
|
1000
|
+
|
|
1001
|
+
export {
|
|
1002
|
+
Documents as Documents,
|
|
1003
|
+
type DocumentCreateResponse as DocumentCreateResponse,
|
|
1004
|
+
type DocumentRetrieveResponse as DocumentRetrieveResponse,
|
|
1005
|
+
type DocumentListResponse as DocumentListResponse,
|
|
1006
|
+
type DocumentListResponsesCursorPage as DocumentListResponsesCursorPage,
|
|
1007
|
+
type DocumentCreateParams as DocumentCreateParams,
|
|
1008
|
+
type DocumentListParams as DocumentListParams,
|
|
1009
|
+
};
|
|
1010
|
+
|
|
1011
|
+
export {
|
|
1012
|
+
RealtimeSessions as RealtimeSessions,
|
|
1013
|
+
type RealtimeSessionCreateResponse as RealtimeSessionCreateResponse,
|
|
1014
|
+
type RealtimeSessionRetrieveResponse as RealtimeSessionRetrieveResponse,
|
|
1015
|
+
type RealtimeSessionCreateParams as RealtimeSessionCreateParams,
|
|
1016
|
+
};
|
|
1017
|
+
|
|
1018
|
+
export {
|
|
1019
|
+
Voices as Voices,
|
|
1020
|
+
type VoiceCreateResponse as VoiceCreateResponse,
|
|
1021
|
+
type VoiceRetrieveResponse as VoiceRetrieveResponse,
|
|
1022
|
+
type VoiceListResponse as VoiceListResponse,
|
|
1023
|
+
type VoicePreviewResponse as VoicePreviewResponse,
|
|
1024
|
+
type VoiceListResponsesCursorPage as VoiceListResponsesCursorPage,
|
|
1025
|
+
type VoiceCreateParams as VoiceCreateParams,
|
|
1026
|
+
type VoiceListParams as VoiceListParams,
|
|
1027
|
+
type VoicePreviewParams as VoicePreviewParams,
|
|
1028
|
+
};
|
|
1029
|
+
|
|
892
1030
|
export {
|
|
893
1031
|
Uploads as Uploads,
|
|
894
1032
|
type UploadCreateEphemeralResponse as UploadCreateEphemeralResponse,
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { RunwayMLError } from './error';
|
|
4
|
+
import { FinalRequestOptions } from '../internal/request-options';
|
|
5
|
+
import { defaultParseResponse } from '../internal/parse';
|
|
6
|
+
import { type RunwayML } from '../client';
|
|
7
|
+
import { APIPromise } from './api-promise';
|
|
8
|
+
import { type APIResponseProps } from '../internal/parse';
|
|
9
|
+
import { maybeObj } from '../internal/utils/values';
|
|
10
|
+
|
|
11
|
+
export type PageRequestOptions = Pick<FinalRequestOptions, 'query' | 'headers' | 'body' | 'path' | 'method'>;
|
|
12
|
+
|
|
13
|
+
export abstract class AbstractPage<Item> implements AsyncIterable<Item> {
|
|
14
|
+
#client: RunwayML;
|
|
15
|
+
protected options: FinalRequestOptions;
|
|
16
|
+
|
|
17
|
+
protected response: Response;
|
|
18
|
+
protected body: unknown;
|
|
19
|
+
|
|
20
|
+
constructor(client: RunwayML, response: Response, body: unknown, options: FinalRequestOptions) {
|
|
21
|
+
this.#client = client;
|
|
22
|
+
this.options = options;
|
|
23
|
+
this.response = response;
|
|
24
|
+
this.body = body;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
abstract nextPageRequestOptions(): PageRequestOptions | null;
|
|
28
|
+
|
|
29
|
+
abstract getPaginatedItems(): Item[];
|
|
30
|
+
|
|
31
|
+
hasNextPage(): boolean {
|
|
32
|
+
const items = this.getPaginatedItems();
|
|
33
|
+
if (!items.length) return false;
|
|
34
|
+
return this.nextPageRequestOptions() != null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async getNextPage(): Promise<this> {
|
|
38
|
+
const nextOptions = this.nextPageRequestOptions();
|
|
39
|
+
if (!nextOptions) {
|
|
40
|
+
throw new RunwayMLError(
|
|
41
|
+
'No next page expected; please check `.hasNextPage()` before calling `.getNextPage()`.',
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return await this.#client.requestAPIList(this.constructor as any, nextOptions);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async *iterPages(): AsyncGenerator<this> {
|
|
49
|
+
let page: this = this;
|
|
50
|
+
yield page;
|
|
51
|
+
while (page.hasNextPage()) {
|
|
52
|
+
page = await page.getNextPage();
|
|
53
|
+
yield page;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async *[Symbol.asyncIterator](): AsyncGenerator<Item> {
|
|
58
|
+
for await (const page of this.iterPages()) {
|
|
59
|
+
for (const item of page.getPaginatedItems()) {
|
|
60
|
+
yield item;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* This subclass of Promise will resolve to an instantiated Page once the request completes.
|
|
68
|
+
*
|
|
69
|
+
* It also implements AsyncIterable to allow auto-paginating iteration on an unawaited list call, eg:
|
|
70
|
+
*
|
|
71
|
+
* for await (const item of client.items.list()) {
|
|
72
|
+
* console.log(item)
|
|
73
|
+
* }
|
|
74
|
+
*/
|
|
75
|
+
export class PagePromise<
|
|
76
|
+
PageClass extends AbstractPage<Item>,
|
|
77
|
+
Item = ReturnType<PageClass['getPaginatedItems']>[number],
|
|
78
|
+
>
|
|
79
|
+
extends APIPromise<PageClass>
|
|
80
|
+
implements AsyncIterable<Item>
|
|
81
|
+
{
|
|
82
|
+
constructor(
|
|
83
|
+
client: RunwayML,
|
|
84
|
+
request: Promise<APIResponseProps>,
|
|
85
|
+
Page: new (...args: ConstructorParameters<typeof AbstractPage>) => PageClass,
|
|
86
|
+
) {
|
|
87
|
+
super(
|
|
88
|
+
client,
|
|
89
|
+
request,
|
|
90
|
+
async (client, props) =>
|
|
91
|
+
new Page(client, props.response, await defaultParseResponse(client, props), props.options),
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Allow auto-paginating iteration on an unawaited list call, eg:
|
|
97
|
+
*
|
|
98
|
+
* for await (const item of client.items.list()) {
|
|
99
|
+
* console.log(item)
|
|
100
|
+
* }
|
|
101
|
+
*/
|
|
102
|
+
async *[Symbol.asyncIterator](): AsyncGenerator<Item> {
|
|
103
|
+
const page = await this;
|
|
104
|
+
for await (const item of page) {
|
|
105
|
+
yield item;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface CursorPageResponse<Item> {
|
|
111
|
+
data: Array<Item>;
|
|
112
|
+
|
|
113
|
+
nextCursor: string;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface CursorPageParams {
|
|
117
|
+
cursor?: string;
|
|
118
|
+
|
|
119
|
+
limit?: number;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export class CursorPage<Item> extends AbstractPage<Item> implements CursorPageResponse<Item> {
|
|
123
|
+
data: Array<Item>;
|
|
124
|
+
|
|
125
|
+
nextCursor: string;
|
|
126
|
+
|
|
127
|
+
constructor(
|
|
128
|
+
client: RunwayML,
|
|
129
|
+
response: Response,
|
|
130
|
+
body: CursorPageResponse<Item>,
|
|
131
|
+
options: FinalRequestOptions,
|
|
132
|
+
) {
|
|
133
|
+
super(client, response, body, options);
|
|
134
|
+
|
|
135
|
+
this.data = body.data || [];
|
|
136
|
+
this.nextCursor = body.nextCursor || '';
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
getPaginatedItems(): Item[] {
|
|
140
|
+
return this.data ?? [];
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
nextPageRequestOptions(): PageRequestOptions | null {
|
|
144
|
+
const cursor = this.nextCursor;
|
|
145
|
+
if (!cursor) {
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return {
|
|
150
|
+
...this.options,
|
|
151
|
+
query: {
|
|
152
|
+
...maybeObj(this.options.query),
|
|
153
|
+
cursor,
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ export { RunwayML as default } from './client';
|
|
|
5
5
|
export { type Uploadable, toFile } from './core/uploads';
|
|
6
6
|
export { APIPromise } from './core/api-promise';
|
|
7
7
|
export { RunwayML, type ClientOptions } from './client';
|
|
8
|
+
export { PagePromise } from './core/pagination';
|
|
8
9
|
export {
|
|
9
10
|
RunwayMLError,
|
|
10
11
|
APIError,
|
package/src/internal/parse.ts
CHANGED
|
@@ -29,6 +29,12 @@ export async function defaultParseResponse<T>(client: RunwayML, props: APIRespon
|
|
|
29
29
|
const mediaType = contentType?.split(';')[0]?.trim();
|
|
30
30
|
const isJSON = mediaType?.includes('application/json') || mediaType?.endsWith('+json');
|
|
31
31
|
if (isJSON) {
|
|
32
|
+
const contentLength = response.headers.get('content-length');
|
|
33
|
+
if (contentLength === '0') {
|
|
34
|
+
// if there is no content we can't do anything
|
|
35
|
+
return undefined as T;
|
|
36
|
+
}
|
|
37
|
+
|
|
32
38
|
const json = await response.json();
|
|
33
39
|
return json as T;
|
|
34
40
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { RunwayMLError } from '../../core/error';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Basic re-implementation of `qs.stringify` for primitive types.
|
|
7
|
+
*/
|
|
8
|
+
export function stringifyQuery(query: object | Record<string, unknown>) {
|
|
9
|
+
return Object.entries(query)
|
|
10
|
+
.filter(([_, value]) => typeof value !== 'undefined')
|
|
11
|
+
.map(([key, value]) => {
|
|
12
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
|
13
|
+
return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
|
14
|
+
}
|
|
15
|
+
if (value === null) {
|
|
16
|
+
return `${encodeURIComponent(key)}=`;
|
|
17
|
+
}
|
|
18
|
+
throw new RunwayMLError(
|
|
19
|
+
`Cannot stringify type ${typeof value}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`,
|
|
20
|
+
);
|
|
21
|
+
})
|
|
22
|
+
.join('&');
|
|
23
|
+
}
|
package/src/internal/utils.ts
CHANGED