@runwayml/sdk 3.14.3 → 3.15.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.
Files changed (209) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +31 -0
  3. package/client.d.mts +52 -1
  4. package/client.d.mts.map +1 -1
  5. package/client.d.ts +52 -1
  6. package/client.d.ts.map +1 -1
  7. package/client.js +63 -17
  8. package/client.js.map +1 -1
  9. package/client.mjs +63 -17
  10. package/client.mjs.map +1 -1
  11. package/core/pagination.d.mts +54 -0
  12. package/core/pagination.d.mts.map +1 -0
  13. package/core/pagination.d.ts +54 -0
  14. package/core/pagination.d.ts.map +1 -0
  15. package/core/pagination.js +101 -0
  16. package/core/pagination.js.map +1 -0
  17. package/core/pagination.mjs +95 -0
  18. package/core/pagination.mjs.map +1 -0
  19. package/index.d.mts +1 -0
  20. package/index.d.mts.map +1 -1
  21. package/index.d.ts +1 -0
  22. package/index.d.ts.map +1 -1
  23. package/index.js +3 -1
  24. package/index.js.map +1 -1
  25. package/index.mjs +1 -0
  26. package/index.mjs.map +1 -1
  27. package/internal/tslib.js +17 -17
  28. package/internal/utils/query.d.mts +5 -0
  29. package/internal/utils/query.d.mts.map +1 -0
  30. package/internal/utils/query.d.ts +5 -0
  31. package/internal/utils/query.d.ts.map +1 -0
  32. package/internal/utils/query.js +23 -0
  33. package/internal/utils/query.js.map +1 -0
  34. package/internal/utils/query.mjs +20 -0
  35. package/internal/utils/query.mjs.map +1 -0
  36. package/internal/utils.d.mts +1 -0
  37. package/internal/utils.d.ts +1 -0
  38. package/internal/utils.js +1 -0
  39. package/internal/utils.js.map +1 -1
  40. package/internal/utils.mjs +1 -0
  41. package/package.json +22 -1
  42. package/pagination.d.mts +2 -0
  43. package/pagination.d.mts.map +1 -0
  44. package/pagination.d.ts +2 -0
  45. package/pagination.d.ts.map +1 -0
  46. package/pagination.js +6 -0
  47. package/pagination.js.map +1 -0
  48. package/pagination.mjs +2 -0
  49. package/pagination.mjs.map +1 -0
  50. package/resources/avatars.d.mts +1308 -0
  51. package/resources/avatars.d.mts.map +1 -0
  52. package/resources/avatars.d.ts +1308 -0
  53. package/resources/avatars.d.ts.map +1 -0
  54. package/resources/avatars.js +87 -0
  55. package/resources/avatars.js.map +1 -0
  56. package/resources/avatars.mjs +83 -0
  57. package/resources/avatars.mjs.map +1 -0
  58. package/resources/character-performance.d.mts +3 -0
  59. package/resources/character-performance.d.mts.map +1 -1
  60. package/resources/character-performance.d.ts +3 -0
  61. package/resources/character-performance.d.ts.map +1 -1
  62. package/resources/character-performance.js +3 -0
  63. package/resources/character-performance.js.map +1 -1
  64. package/resources/character-performance.mjs +3 -0
  65. package/resources/character-performance.mjs.map +1 -1
  66. package/resources/documents.d.mts +209 -0
  67. package/resources/documents.d.mts.map +1 -0
  68. package/resources/documents.d.ts +209 -0
  69. package/resources/documents.d.ts.map +1 -0
  70. package/resources/documents.js +75 -0
  71. package/resources/documents.js.map +1 -0
  72. package/resources/documents.mjs +71 -0
  73. package/resources/documents.mjs.map +1 -0
  74. package/resources/image-to-video.d.mts +3 -0
  75. package/resources/image-to-video.d.mts.map +1 -1
  76. package/resources/image-to-video.d.ts +3 -0
  77. package/resources/image-to-video.d.ts.map +1 -1
  78. package/resources/image-to-video.js +3 -0
  79. package/resources/image-to-video.js.map +1 -1
  80. package/resources/image-to-video.mjs +3 -0
  81. package/resources/image-to-video.mjs.map +1 -1
  82. package/resources/index.d.mts +4 -0
  83. package/resources/index.d.mts.map +1 -1
  84. package/resources/index.d.ts +4 -0
  85. package/resources/index.d.ts.map +1 -1
  86. package/resources/index.js +9 -1
  87. package/resources/index.js.map +1 -1
  88. package/resources/index.mjs +4 -0
  89. package/resources/index.mjs.map +1 -1
  90. package/resources/organization.d.mts +2 -2
  91. package/resources/organization.d.mts.map +1 -1
  92. package/resources/organization.d.ts +2 -2
  93. package/resources/organization.d.ts.map +1 -1
  94. package/resources/realtime-sessions.d.mts +180 -0
  95. package/resources/realtime-sessions.d.mts.map +1 -0
  96. package/resources/realtime-sessions.d.ts +180 -0
  97. package/resources/realtime-sessions.d.ts.map +1 -0
  98. package/resources/realtime-sessions.js +32 -0
  99. package/resources/realtime-sessions.js.map +1 -0
  100. package/resources/realtime-sessions.mjs +28 -0
  101. package/resources/realtime-sessions.mjs.map +1 -0
  102. package/resources/sound-effect.d.mts +3 -0
  103. package/resources/sound-effect.d.mts.map +1 -1
  104. package/resources/sound-effect.d.ts +3 -0
  105. package/resources/sound-effect.d.ts.map +1 -1
  106. package/resources/sound-effect.js +3 -0
  107. package/resources/sound-effect.js.map +1 -1
  108. package/resources/sound-effect.mjs +3 -0
  109. package/resources/sound-effect.mjs.map +1 -1
  110. package/resources/speech-to-speech.d.mts +3 -0
  111. package/resources/speech-to-speech.d.mts.map +1 -1
  112. package/resources/speech-to-speech.d.ts +3 -0
  113. package/resources/speech-to-speech.d.ts.map +1 -1
  114. package/resources/speech-to-speech.js +3 -0
  115. package/resources/speech-to-speech.js.map +1 -1
  116. package/resources/speech-to-speech.mjs +3 -0
  117. package/resources/speech-to-speech.mjs.map +1 -1
  118. package/resources/tasks.d.mts +3 -0
  119. package/resources/tasks.d.mts.map +1 -1
  120. package/resources/tasks.d.ts +3 -0
  121. package/resources/tasks.d.ts.map +1 -1
  122. package/resources/tasks.js +3 -0
  123. package/resources/tasks.js.map +1 -1
  124. package/resources/tasks.mjs +3 -0
  125. package/resources/tasks.mjs.map +1 -1
  126. package/resources/text-to-image.d.mts +3 -0
  127. package/resources/text-to-image.d.mts.map +1 -1
  128. package/resources/text-to-image.d.ts +3 -0
  129. package/resources/text-to-image.d.ts.map +1 -1
  130. package/resources/text-to-image.js +3 -0
  131. package/resources/text-to-image.js.map +1 -1
  132. package/resources/text-to-image.mjs +3 -0
  133. package/resources/text-to-image.mjs.map +1 -1
  134. package/resources/text-to-speech.d.mts +3 -0
  135. package/resources/text-to-speech.d.mts.map +1 -1
  136. package/resources/text-to-speech.d.ts +3 -0
  137. package/resources/text-to-speech.d.ts.map +1 -1
  138. package/resources/text-to-speech.js +3 -0
  139. package/resources/text-to-speech.js.map +1 -1
  140. package/resources/text-to-speech.mjs +3 -0
  141. package/resources/text-to-speech.mjs.map +1 -1
  142. package/resources/text-to-video.d.mts +3 -0
  143. package/resources/text-to-video.d.mts.map +1 -1
  144. package/resources/text-to-video.d.ts +3 -0
  145. package/resources/text-to-video.d.ts.map +1 -1
  146. package/resources/text-to-video.js +3 -0
  147. package/resources/text-to-video.js.map +1 -1
  148. package/resources/text-to-video.mjs +3 -0
  149. package/resources/text-to-video.mjs.map +1 -1
  150. package/resources/video-to-video.d.mts +3 -0
  151. package/resources/video-to-video.d.mts.map +1 -1
  152. package/resources/video-to-video.d.ts +3 -0
  153. package/resources/video-to-video.d.ts.map +1 -1
  154. package/resources/video-to-video.js +3 -0
  155. package/resources/video-to-video.js.map +1 -1
  156. package/resources/video-to-video.mjs +3 -0
  157. package/resources/video-to-video.mjs.map +1 -1
  158. package/resources/voice-dubbing.d.mts +3 -0
  159. package/resources/voice-dubbing.d.mts.map +1 -1
  160. package/resources/voice-dubbing.d.ts +3 -0
  161. package/resources/voice-dubbing.d.ts.map +1 -1
  162. package/resources/voice-dubbing.js +3 -0
  163. package/resources/voice-dubbing.js.map +1 -1
  164. package/resources/voice-dubbing.mjs +3 -0
  165. package/resources/voice-dubbing.mjs.map +1 -1
  166. package/resources/voice-isolation.d.mts +3 -0
  167. package/resources/voice-isolation.d.mts.map +1 -1
  168. package/resources/voice-isolation.d.ts +3 -0
  169. package/resources/voice-isolation.d.ts.map +1 -1
  170. package/resources/voice-isolation.js +3 -0
  171. package/resources/voice-isolation.js.map +1 -1
  172. package/resources/voice-isolation.mjs +3 -0
  173. package/resources/voice-isolation.mjs.map +1 -1
  174. package/resources/voices.d.mts +257 -0
  175. package/resources/voices.d.mts.map +1 -0
  176. package/resources/voices.d.ts +257 -0
  177. package/resources/voices.d.ts.map +1 -0
  178. package/resources/voices.js +47 -0
  179. package/resources/voices.js.map +1 -0
  180. package/resources/voices.mjs +43 -0
  181. package/resources/voices.mjs.map +1 -0
  182. package/src/client.ts +159 -22
  183. package/src/core/pagination.ts +157 -0
  184. package/src/index.ts +1 -0
  185. package/src/internal/utils/query.ts +23 -0
  186. package/src/internal/utils.ts +1 -0
  187. package/src/pagination.ts +2 -0
  188. package/src/resources/avatars.ts +2049 -0
  189. package/src/resources/character-performance.ts +3 -0
  190. package/src/resources/documents.ts +270 -0
  191. package/src/resources/image-to-video.ts +3 -0
  192. package/src/resources/index.ts +37 -0
  193. package/src/resources/organization.ts +5 -1
  194. package/src/resources/realtime-sessions.ts +251 -0
  195. package/src/resources/sound-effect.ts +3 -0
  196. package/src/resources/speech-to-speech.ts +3 -0
  197. package/src/resources/tasks.ts +3 -0
  198. package/src/resources/text-to-image.ts +3 -0
  199. package/src/resources/text-to-speech.ts +3 -0
  200. package/src/resources/text-to-video.ts +3 -0
  201. package/src/resources/video-to-video.ts +3 -0
  202. package/src/resources/voice-dubbing.ts +3 -0
  203. package/src/resources/voice-isolation.ts +3 -0
  204. package/src/resources/voices.ts +345 -0
  205. package/src/version.ts +1 -1
  206. package/version.d.mts +1 -1
  207. package/version.d.ts +1 -1
  208. package/version.js +1 -1
  209. package/version.mjs +1 -1
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,
@@ -62,6 +91,17 @@ import {
62
91
  VoiceIsolationCreateResponse,
63
92
  } from './resources/voice-isolation';
64
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';
65
105
  import { type Fetch } from './internal/builtin-types';
66
106
  import { isRunningInBrowser } from './internal/detect-platform';
67
107
  import { HeadersLike, NullableHeaders, buildHeaders } from './internal/headers';
@@ -273,21 +313,8 @@ export class RunwayML {
273
313
  /**
274
314
  * Basic re-implementation of `qs.stringify` for primitive types.
275
315
  */
276
- protected stringifyQuery(query: Record<string, unknown>): string {
277
- return Object.entries(query)
278
- .filter(([_, value]) => typeof value !== 'undefined')
279
- .map(([key, value]) => {
280
- if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
281
- return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
282
- }
283
- if (value === null) {
284
- return `${encodeURIComponent(key)}=`;
285
- }
286
- throw new Errors.RunwayMLError(
287
- `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.`,
288
- );
289
- })
290
- .join('&');
316
+ protected stringifyQuery(query: object | Record<string, unknown>): string {
317
+ return stringifyQuery(query);
291
318
  }
292
319
 
293
320
  private getUserAgent(): string {
@@ -319,12 +346,13 @@ export class RunwayML {
319
346
  : new URL(baseURL + (baseURL.endsWith('/') && path.startsWith('/') ? path.slice(1) : path));
320
347
 
321
348
  const defaultQuery = this.defaultQuery();
322
- if (!isEmptyObj(defaultQuery)) {
323
- query = { ...defaultQuery, ...query };
349
+ const pathQuery = Object.fromEntries(url.searchParams);
350
+ if (!isEmptyObj(defaultQuery) || !isEmptyObj(pathQuery)) {
351
+ query = { ...pathQuery, ...defaultQuery, ...query };
324
352
  }
325
353
 
326
354
  if (typeof query === 'object' && query && !Array.isArray(query)) {
327
- url.search = this.stringifyQuery(query as Record<string, unknown>);
355
+ url.search = this.stringifyQuery(query);
328
356
  }
329
357
 
330
358
  return url.toString();
@@ -542,6 +570,30 @@ export class RunwayML {
542
570
  return { response, options, controller, requestLogID, retryOfRequestLogID, startTime };
543
571
  }
544
572
 
573
+ getAPIList<Item, PageClass extends Pagination.AbstractPage<Item> = Pagination.AbstractPage<Item>>(
574
+ path: string,
575
+ Page: new (...args: any[]) => PageClass,
576
+ opts?: PromiseOrValue<RequestOptions>,
577
+ ): Pagination.PagePromise<PageClass, Item> {
578
+ return this.requestAPIList(
579
+ Page,
580
+ opts && 'then' in opts ?
581
+ opts.then((opts) => ({ method: 'get', path, ...opts }))
582
+ : { method: 'get', path, ...opts },
583
+ );
584
+ }
585
+
586
+ requestAPIList<
587
+ Item = unknown,
588
+ PageClass extends Pagination.AbstractPage<Item> = Pagination.AbstractPage<Item>,
589
+ >(
590
+ Page: new (...args: ConstructorParameters<typeof Pagination.AbstractPage>) => PageClass,
591
+ options: PromiseOrValue<FinalRequestOptions>,
592
+ ): Pagination.PagePromise<PageClass, Item> {
593
+ const request = this.makeRequest(options, null, undefined);
594
+ return new Pagination.PagePromise<PageClass, Item>(this as any as RunwayML, request, Page);
595
+ }
596
+
545
597
  async fetchWithTimeout(
546
598
  url: RequestInfo,
547
599
  init: RequestInit | undefined,
@@ -629,9 +681,9 @@ export class RunwayML {
629
681
  }
630
682
  }
631
683
 
632
- // If the API asks us to wait a certain amount of time (and it's a reasonable amount),
633
- // just do what it says, but otherwise calculate a default
634
- if (!(timeoutMillis && 0 <= timeoutMillis && timeoutMillis < 60 * 1000)) {
684
+ // If the API asks us to wait a certain amount of time, just do what it
685
+ // says, but otherwise calculate a default
686
+ if (timeoutMillis === undefined) {
635
687
  const maxRetries = options.maxRetries ?? this.maxRetries;
636
688
  timeoutMillis = this.calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries);
637
689
  }
@@ -764,7 +816,7 @@ export class RunwayML {
764
816
  ) {
765
817
  return {
766
818
  bodyHeaders: { 'content-type': 'application/x-www-form-urlencoded' },
767
- body: this.stringifyQuery(body as Record<string, unknown>),
819
+ body: this.stringifyQuery(body),
768
820
  };
769
821
  } else {
770
822
  return this.#encoder({ body, headers });
@@ -790,18 +842,55 @@ export class RunwayML {
790
842
 
791
843
  static toFile = UploadsCore.toFile;
792
844
 
845
+ /**
846
+ * Endpoints for managing tasks that have been submitted.
847
+ */
793
848
  tasks: API.Tasks = new API.Tasks(this);
849
+ /**
850
+ * These endpoints all kick off tasks to create generations.
851
+ */
794
852
  imageToVideo: API.ImageToVideo = new API.ImageToVideo(this);
853
+ /**
854
+ * These endpoints all kick off tasks to create generations.
855
+ */
795
856
  videoToVideo: API.VideoToVideo = new API.VideoToVideo(this);
857
+ /**
858
+ * These endpoints all kick off tasks to create generations.
859
+ */
796
860
  textToVideo: API.TextToVideo = new API.TextToVideo(this);
861
+ /**
862
+ * These endpoints all kick off tasks to create generations.
863
+ */
797
864
  textToImage: API.TextToImage = new API.TextToImage(this);
865
+ /**
866
+ * These endpoints all kick off tasks to create generations.
867
+ */
798
868
  characterPerformance: API.CharacterPerformance = new API.CharacterPerformance(this);
869
+ /**
870
+ * These endpoints all kick off tasks to create generations.
871
+ */
799
872
  textToSpeech: API.TextToSpeech = new API.TextToSpeech(this);
873
+ /**
874
+ * These endpoints all kick off tasks to create generations.
875
+ */
800
876
  soundEffect: API.SoundEffect = new API.SoundEffect(this);
877
+ /**
878
+ * These endpoints all kick off tasks to create generations.
879
+ */
801
880
  voiceIsolation: API.VoiceIsolation = new API.VoiceIsolation(this);
881
+ /**
882
+ * These endpoints all kick off tasks to create generations.
883
+ */
802
884
  voiceDubbing: API.VoiceDubbing = new API.VoiceDubbing(this);
885
+ /**
886
+ * These endpoints all kick off tasks to create generations.
887
+ */
803
888
  speechToSpeech: API.SpeechToSpeech = new API.SpeechToSpeech(this);
804
889
  organization: API.Organization = new API.Organization(this);
890
+ avatars: API.Avatars = new API.Avatars(this);
891
+ documents: API.Documents = new API.Documents(this);
892
+ realtimeSessions: API.RealtimeSessions = new API.RealtimeSessions(this);
893
+ voices: API.Voices = new API.Voices(this);
805
894
  uploads: API.Uploads = new API.Uploads(this);
806
895
  }
807
896
 
@@ -817,11 +906,18 @@ RunwayML.VoiceIsolation = VoiceIsolation;
817
906
  RunwayML.VoiceDubbing = VoiceDubbing;
818
907
  RunwayML.SpeechToSpeech = SpeechToSpeech;
819
908
  RunwayML.Organization = Organization;
909
+ RunwayML.Avatars = Avatars;
910
+ RunwayML.Documents = Documents;
911
+ RunwayML.RealtimeSessions = RealtimeSessions;
912
+ RunwayML.Voices = Voices;
820
913
  RunwayML.Uploads = Uploads;
821
914
 
822
915
  export declare namespace RunwayML {
823
916
  export type RequestOptions = Opts.RequestOptions;
824
917
 
918
+ export import CursorPage = Pagination.CursorPage;
919
+ export { type CursorPageParams as CursorPageParams, type CursorPageResponse as CursorPageResponse };
920
+
825
921
  export { Tasks as Tasks, type TaskRetrieveResponse as TaskRetrieveResponse };
826
922
 
827
923
  export {
@@ -891,6 +987,47 @@ export declare namespace RunwayML {
891
987
  type OrganizationRetrieveUsageParams as OrganizationRetrieveUsageParams,
892
988
  };
893
989
 
990
+ export {
991
+ Avatars as Avatars,
992
+ type AvatarCreateResponse as AvatarCreateResponse,
993
+ type AvatarRetrieveResponse as AvatarRetrieveResponse,
994
+ type AvatarUpdateResponse as AvatarUpdateResponse,
995
+ type AvatarListResponse as AvatarListResponse,
996
+ type AvatarListResponsesCursorPage as AvatarListResponsesCursorPage,
997
+ type AvatarCreateParams as AvatarCreateParams,
998
+ type AvatarUpdateParams as AvatarUpdateParams,
999
+ type AvatarListParams as AvatarListParams,
1000
+ };
1001
+
1002
+ export {
1003
+ Documents as Documents,
1004
+ type DocumentCreateResponse as DocumentCreateResponse,
1005
+ type DocumentRetrieveResponse as DocumentRetrieveResponse,
1006
+ type DocumentListResponse as DocumentListResponse,
1007
+ type DocumentListResponsesCursorPage as DocumentListResponsesCursorPage,
1008
+ type DocumentCreateParams as DocumentCreateParams,
1009
+ type DocumentListParams as DocumentListParams,
1010
+ };
1011
+
1012
+ export {
1013
+ RealtimeSessions as RealtimeSessions,
1014
+ type RealtimeSessionCreateResponse as RealtimeSessionCreateResponse,
1015
+ type RealtimeSessionRetrieveResponse as RealtimeSessionRetrieveResponse,
1016
+ type RealtimeSessionCreateParams as RealtimeSessionCreateParams,
1017
+ };
1018
+
1019
+ export {
1020
+ Voices as Voices,
1021
+ type VoiceCreateResponse as VoiceCreateResponse,
1022
+ type VoiceRetrieveResponse as VoiceRetrieveResponse,
1023
+ type VoiceListResponse as VoiceListResponse,
1024
+ type VoicePreviewResponse as VoicePreviewResponse,
1025
+ type VoiceListResponsesCursorPage as VoiceListResponsesCursorPage,
1026
+ type VoiceCreateParams as VoiceCreateParams,
1027
+ type VoiceListParams as VoiceListParams,
1028
+ type VoicePreviewParams as VoicePreviewParams,
1029
+ };
1030
+
894
1031
  export {
895
1032
  Uploads as Uploads,
896
1033
  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,
@@ -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
+ }
@@ -6,3 +6,4 @@ export * from './utils/env';
6
6
  export * from './utils/log';
7
7
  export * from './utils/uuid';
8
8
  export * from './utils/sleep';
9
+ export * from './utils/query';
@@ -0,0 +1,2 @@
1
+ /** @deprecated Import from ./core/pagination instead */
2
+ export * from './core/pagination';