@runwayml/sdk 3.14.3 → 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.
Files changed (209) hide show
  1. package/CHANGELOG.md +20 -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 +60 -15
  8. package/client.js.map +1 -1
  9. package/client.mjs +60 -15
  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 +11 -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 +156 -20
  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 {
@@ -324,7 +351,7 @@ export class RunwayML {
324
351
  }
325
352
 
326
353
  if (typeof query === 'object' && query && !Array.isArray(query)) {
327
- url.search = this.stringifyQuery(query as Record<string, unknown>);
354
+ url.search = this.stringifyQuery(query);
328
355
  }
329
356
 
330
357
  return url.toString();
@@ -542,6 +569,30 @@ export class RunwayML {
542
569
  return { response, options, controller, requestLogID, retryOfRequestLogID, startTime };
543
570
  }
544
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
+
545
596
  async fetchWithTimeout(
546
597
  url: RequestInfo,
547
598
  init: RequestInit | undefined,
@@ -629,9 +680,9 @@ export class RunwayML {
629
680
  }
630
681
  }
631
682
 
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)) {
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) {
635
686
  const maxRetries = options.maxRetries ?? this.maxRetries;
636
687
  timeoutMillis = this.calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries);
637
688
  }
@@ -764,7 +815,7 @@ export class RunwayML {
764
815
  ) {
765
816
  return {
766
817
  bodyHeaders: { 'content-type': 'application/x-www-form-urlencoded' },
767
- body: this.stringifyQuery(body as Record<string, unknown>),
818
+ body: this.stringifyQuery(body),
768
819
  };
769
820
  } else {
770
821
  return this.#encoder({ body, headers });
@@ -790,18 +841,55 @@ export class RunwayML {
790
841
 
791
842
  static toFile = UploadsCore.toFile;
792
843
 
844
+ /**
845
+ * Endpoints for managing tasks that have been submitted.
846
+ */
793
847
  tasks: API.Tasks = new API.Tasks(this);
848
+ /**
849
+ * These endpoints all kick off tasks to create generations.
850
+ */
794
851
  imageToVideo: API.ImageToVideo = new API.ImageToVideo(this);
852
+ /**
853
+ * These endpoints all kick off tasks to create generations.
854
+ */
795
855
  videoToVideo: API.VideoToVideo = new API.VideoToVideo(this);
856
+ /**
857
+ * These endpoints all kick off tasks to create generations.
858
+ */
796
859
  textToVideo: API.TextToVideo = new API.TextToVideo(this);
860
+ /**
861
+ * These endpoints all kick off tasks to create generations.
862
+ */
797
863
  textToImage: API.TextToImage = new API.TextToImage(this);
864
+ /**
865
+ * These endpoints all kick off tasks to create generations.
866
+ */
798
867
  characterPerformance: API.CharacterPerformance = new API.CharacterPerformance(this);
868
+ /**
869
+ * These endpoints all kick off tasks to create generations.
870
+ */
799
871
  textToSpeech: API.TextToSpeech = new API.TextToSpeech(this);
872
+ /**
873
+ * These endpoints all kick off tasks to create generations.
874
+ */
800
875
  soundEffect: API.SoundEffect = new API.SoundEffect(this);
876
+ /**
877
+ * These endpoints all kick off tasks to create generations.
878
+ */
801
879
  voiceIsolation: API.VoiceIsolation = new API.VoiceIsolation(this);
880
+ /**
881
+ * These endpoints all kick off tasks to create generations.
882
+ */
802
883
  voiceDubbing: API.VoiceDubbing = new API.VoiceDubbing(this);
884
+ /**
885
+ * These endpoints all kick off tasks to create generations.
886
+ */
803
887
  speechToSpeech: API.SpeechToSpeech = new API.SpeechToSpeech(this);
804
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);
805
893
  uploads: API.Uploads = new API.Uploads(this);
806
894
  }
807
895
 
@@ -817,11 +905,18 @@ RunwayML.VoiceIsolation = VoiceIsolation;
817
905
  RunwayML.VoiceDubbing = VoiceDubbing;
818
906
  RunwayML.SpeechToSpeech = SpeechToSpeech;
819
907
  RunwayML.Organization = Organization;
908
+ RunwayML.Avatars = Avatars;
909
+ RunwayML.Documents = Documents;
910
+ RunwayML.RealtimeSessions = RealtimeSessions;
911
+ RunwayML.Voices = Voices;
820
912
  RunwayML.Uploads = Uploads;
821
913
 
822
914
  export declare namespace RunwayML {
823
915
  export type RequestOptions = Opts.RequestOptions;
824
916
 
917
+ export import CursorPage = Pagination.CursorPage;
918
+ export { type CursorPageParams as CursorPageParams, type CursorPageResponse as CursorPageResponse };
919
+
825
920
  export { Tasks as Tasks, type TaskRetrieveResponse as TaskRetrieveResponse };
826
921
 
827
922
  export {
@@ -891,6 +986,47 @@ export declare namespace RunwayML {
891
986
  type OrganizationRetrieveUsageParams as OrganizationRetrieveUsageParams,
892
987
  };
893
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
+
894
1030
  export {
895
1031
  Uploads as Uploads,
896
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,
@@ -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';