@runappsai/sdk 0.0.0-stage → 0.3.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 (105) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +274 -2
  3. package/dist/activity-tracker.d.ts +113 -0
  4. package/dist/activity-tracker.d.ts.map +1 -0
  5. package/dist/activity-tracker.js +176 -0
  6. package/dist/activity-tracker.js.map +1 -0
  7. package/dist/audio.d.ts +129 -0
  8. package/dist/audio.d.ts.map +1 -0
  9. package/dist/audio.js +267 -0
  10. package/dist/audio.js.map +1 -0
  11. package/dist/browser-auth.d.ts +179 -0
  12. package/dist/browser-auth.d.ts.map +1 -0
  13. package/dist/browser-auth.js +1361 -0
  14. package/dist/browser-auth.js.map +1 -0
  15. package/dist/chat.d.ts +221 -0
  16. package/dist/chat.d.ts.map +1 -0
  17. package/dist/chat.js +155 -0
  18. package/dist/chat.js.map +1 -0
  19. package/dist/client.d.ts +155 -0
  20. package/dist/client.d.ts.map +1 -0
  21. package/dist/client.js +157 -0
  22. package/dist/client.js.map +1 -0
  23. package/dist/computer.d.ts +57 -0
  24. package/dist/computer.d.ts.map +1 -0
  25. package/dist/computer.js +21 -0
  26. package/dist/computer.js.map +1 -0
  27. package/dist/embeddings.d.ts +64 -0
  28. package/dist/embeddings.d.ts.map +1 -0
  29. package/dist/embeddings.js +30 -0
  30. package/dist/embeddings.js.map +1 -0
  31. package/dist/errors.d.ts +24 -0
  32. package/dist/errors.d.ts.map +1 -0
  33. package/dist/errors.js +29 -0
  34. package/dist/errors.js.map +1 -0
  35. package/dist/event-wrap.d.ts +59 -0
  36. package/dist/event-wrap.d.ts.map +1 -0
  37. package/dist/event-wrap.js +142 -0
  38. package/dist/event-wrap.js.map +1 -0
  39. package/dist/events.d.ts +119 -0
  40. package/dist/events.d.ts.map +1 -0
  41. package/dist/events.js +87 -0
  42. package/dist/events.js.map +1 -0
  43. package/dist/files.d.ts +218 -0
  44. package/dist/files.d.ts.map +1 -0
  45. package/dist/files.js +212 -0
  46. package/dist/files.js.map +1 -0
  47. package/dist/image.d.ts +185 -0
  48. package/dist/image.d.ts.map +1 -0
  49. package/dist/image.js +148 -0
  50. package/dist/image.js.map +1 -0
  51. package/dist/index.d.ts +30 -0
  52. package/dist/index.d.ts.map +1 -0
  53. package/dist/index.js +26 -0
  54. package/dist/index.js.map +1 -0
  55. package/dist/media.d.ts +56 -0
  56. package/dist/media.d.ts.map +1 -0
  57. package/dist/media.js +133 -0
  58. package/dist/media.js.map +1 -0
  59. package/dist/model_options.d.ts +165 -0
  60. package/dist/model_options.d.ts.map +1 -0
  61. package/dist/model_options.js +59 -0
  62. package/dist/model_options.js.map +1 -0
  63. package/dist/models.d.ts +88 -0
  64. package/dist/models.d.ts.map +1 -0
  65. package/dist/models.js +55 -0
  66. package/dist/models.js.map +1 -0
  67. package/dist/sdk.umd.js +4 -0
  68. package/dist/sdk.umd.js.map +1 -0
  69. package/dist/transport.d.ts +120 -0
  70. package/dist/transport.d.ts.map +1 -0
  71. package/dist/transport.js +214 -0
  72. package/dist/transport.js.map +1 -0
  73. package/dist/types.d.ts +31 -0
  74. package/dist/types.d.ts.map +1 -0
  75. package/dist/types.js +2 -0
  76. package/dist/types.js.map +1 -0
  77. package/dist/validate.d.ts +16 -0
  78. package/dist/validate.d.ts.map +1 -0
  79. package/dist/validate.js +329 -0
  80. package/dist/validate.js.map +1 -0
  81. package/dist/video.d.ts +134 -0
  82. package/dist/video.d.ts.map +1 -0
  83. package/dist/video.js +60 -0
  84. package/dist/video.js.map +1 -0
  85. package/package.json +54 -4
  86. package/src/activity-tracker.ts +251 -0
  87. package/src/audio.ts +440 -0
  88. package/src/browser-auth.ts +1529 -0
  89. package/src/chat.ts +368 -0
  90. package/src/client.ts +250 -0
  91. package/src/computer.ts +80 -0
  92. package/src/embeddings.ts +97 -0
  93. package/src/errors.ts +29 -0
  94. package/src/event-wrap.ts +168 -0
  95. package/src/events.ts +172 -0
  96. package/src/files.ts +347 -0
  97. package/src/image.ts +339 -0
  98. package/src/index.ts +151 -0
  99. package/src/media.ts +147 -0
  100. package/src/model_options.ts +220 -0
  101. package/src/models.ts +121 -0
  102. package/src/transport.ts +292 -0
  103. package/src/types.ts +31 -0
  104. package/src/validate.ts +364 -0
  105. package/src/video.ts +215 -0
package/src/video.ts ADDED
@@ -0,0 +1,215 @@
1
+ import type { Transport } from "./transport.js";
2
+ import type { Usage } from "./types.js";
3
+ import type { SDKEvents } from "./events.js";
4
+ import { wrapEvents } from "./event-wrap.js";
5
+
6
+ /* ------------------------------------------------------------------ */
7
+ /* Request */
8
+ /* ------------------------------------------------------------------ */
9
+
10
+ /**
11
+ * Video generation params. Most fields map 1:1 to the gateway's
12
+ * `/v1/videos/generations` body. Optional booleans (`generate_audio`,
13
+ * `watermark`, `camera_fixed`, `return_last_frame`, `draft`) are
14
+ * tri-state — omit to use the upstream default; explicit `false`
15
+ * forces off.
16
+ */
17
+ export interface VideoGenerateParams {
18
+ prompt: string;
19
+ aspect_ratio?: string;
20
+ duration?: number;
21
+ resolution?: string;
22
+ generate_audio?: boolean;
23
+
24
+ /**
25
+ * First / last frame keyframes (image-to-video). Each accepts:
26
+ * - hosted https:// URL
27
+ * - data:image/...;base64,<payload> URI (use `encodeImageUrl`)
28
+ *
29
+ * The previous `first_frame_b64` / `last_frame_b64` sibling fields
30
+ * were removed — wrap raw bytes in a data: URI client-side via
31
+ * `encodeImageUrl` and pass through `*_url` instead.
32
+ */
33
+ first_frame_url?: string;
34
+ last_frame_url?: string;
35
+
36
+ /**
37
+ * Multimodal reference inputs (Seedance 2.0). Each entry can be a
38
+ * hosted URL or a data: URI (use `encodeImageUrl` for raw bytes).
39
+ * `reference_images_b64` was removed — fold any raw-base64 entries
40
+ * into `reference_image_urls` as data: URIs.
41
+ */
42
+ reference_image_urls?: string[];
43
+ reference_video_urls?: string[];
44
+ reference_audio_urls?: string[];
45
+
46
+ /** Single-input drivers (video-edit / motion-transfer / lip-sync). */
47
+ source_video_url?: string;
48
+ source_image_url?: string;
49
+ source_audio_url?: string;
50
+
51
+ watermark?: boolean;
52
+ camera_fixed?: boolean;
53
+ return_last_frame?: boolean;
54
+ seed?: number;
55
+
56
+ /** Alternative to `duration` for Seedance 1.0 pro / lite. */
57
+ frames?: number;
58
+
59
+ /** Seedance 1.5 pro Draft Mode. */
60
+ draft?: boolean;
61
+ draft_task_id?: string;
62
+
63
+ /** "flex" = offline (~50% price); pair with execution_expires_after. */
64
+ service_tier?: string;
65
+ execution_expires_after?: number;
66
+
67
+ /** Webhook for state-transition notifications. */
68
+ callback_url?: string;
69
+ user?: string;
70
+
71
+ /** Pass-through for provider-specific knobs. */
72
+ [extra: string]: unknown;
73
+ }
74
+
75
+ /* ------------------------------------------------------------------ */
76
+ /* Response */
77
+ /* ------------------------------------------------------------------ */
78
+
79
+ export interface VideoTask {
80
+ id: string;
81
+ status: string;
82
+ usage: Usage;
83
+ }
84
+
85
+ export interface VideoUsageTokens {
86
+ completion_tokens?: number;
87
+ total_tokens?: number;
88
+ }
89
+
90
+ export interface VideoStatus {
91
+ id: string;
92
+ status: string;
93
+ progress: number;
94
+ video_url?: string;
95
+ error?: string;
96
+ /** Final frame as a separate image — populated when return_last_frame=true. */
97
+ last_frame_url?: string;
98
+ /** Seedance Draft Mode Step1 task id, exposed when the draft succeeds. */
99
+ draft_task_id?: string;
100
+ duration?: number;
101
+ fps?: number;
102
+ resolution?: string;
103
+ ratio?: string;
104
+ seed?: number;
105
+ service_tier?: string;
106
+ /** Upstream-reported tokens (Seedance bills per output token). */
107
+ usage_tokens?: VideoUsageTokens;
108
+ created_at?: number;
109
+ updated_at?: number;
110
+ /**
111
+ * Human-readable credit line that the client SHOULD display alongside
112
+ * the video. Populated by stock-library models (Pexels) whose terms
113
+ * of service require crediting the contributor; AI generators leave
114
+ * it empty. Render verbatim — don't try to parse the format. See
115
+ * ImageResult.attribution for the same convention.
116
+ */
117
+ attribution?: string;
118
+ }
119
+
120
+ /* ------------------------------------------------------------------ */
121
+ /* Service */
122
+ /* ------------------------------------------------------------------ */
123
+
124
+ export interface WaitOptions {
125
+ /** Defaults to 5000ms. */
126
+ pollIntervalMs?: number;
127
+ signal?: AbortSignal;
128
+ }
129
+
130
+ export class VideoService {
131
+ constructor(
132
+ private readonly transport: Transport,
133
+ private readonly events: SDKEvents,
134
+ ) {}
135
+
136
+ /** Submit a video generation task.
137
+ *
138
+ * Telemetry note: only the submit step fires start/end on
139
+ * `client.events` — the per-call latency reflects the gateway
140
+ * accepting the job, NOT how long upstream takes to render. The
141
+ * caller's poll loop sees status flips but the SDK doesn't emit
142
+ * end events for those (would otherwise leave the badge "active"
143
+ * for as long as the upstream renders, sometimes minutes). */
144
+ async generate(
145
+ model: string,
146
+ params: VideoGenerateParams,
147
+ init?: { signal?: AbortSignal },
148
+ ): Promise<VideoTask> {
149
+ return wrapEvents(
150
+ this.events,
151
+ { model, capability: "video_generation" },
152
+ () =>
153
+ this.transport.postJSON<VideoTask>(
154
+ "/v1/videos/generations",
155
+ { model, ...params },
156
+ init,
157
+ ),
158
+ );
159
+ }
160
+
161
+ /** Fetch the current status of a task. */
162
+ async getStatus(
163
+ taskID: string,
164
+ init?: { signal?: AbortSignal },
165
+ ): Promise<VideoStatus> {
166
+ return this.transport.getJSON<VideoStatus>(
167
+ `/v1/videos/generations/${encodeURIComponent(taskID)}`,
168
+ init,
169
+ );
170
+ }
171
+
172
+ /**
173
+ * Poll `getStatus()` until the task reaches a terminal state
174
+ * (`succeeded` / `failed`). Default poll interval is 5s.
175
+ */
176
+ async wait(taskID: string, opts: WaitOptions = {}): Promise<VideoStatus> {
177
+ const interval = opts.pollIntervalMs ?? 5000;
178
+ while (true) {
179
+ const status = await this.getStatus(taskID, { signal: opts.signal });
180
+ if (status.status === "succeeded" || status.status === "failed") {
181
+ return status;
182
+ }
183
+ await sleep(interval, opts.signal);
184
+ }
185
+ }
186
+
187
+ /** Download the raw video bytes for a completed task. */
188
+ async getContent(
189
+ taskID: string,
190
+ init?: { signal?: AbortSignal },
191
+ ): Promise<{ data: Uint8Array; contentType: string }> {
192
+ return this.transport.getRaw(
193
+ `/v1/videos/${encodeURIComponent(taskID)}/content`,
194
+ init,
195
+ );
196
+ }
197
+ }
198
+
199
+ function sleep(ms: number, signal?: AbortSignal): Promise<void> {
200
+ return new Promise((resolve, reject) => {
201
+ if (signal?.aborted) {
202
+ reject(signal.reason ?? new Error("aborted"));
203
+ return;
204
+ }
205
+ const timer = setTimeout(() => {
206
+ signal?.removeEventListener("abort", onAbort);
207
+ resolve();
208
+ }, ms);
209
+ const onAbort = () => {
210
+ clearTimeout(timer);
211
+ reject(signal!.reason ?? new Error("aborted"));
212
+ };
213
+ signal?.addEventListener("abort", onAbort, { once: true });
214
+ });
215
+ }