@remotion-studio/sdk 0.1.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/README.md +369 -0
- package/dist/runtime/compiler.d.ts +7 -0
- package/dist/runtime/compiler.js +131 -0
- package/dist/runtime/components.d.ts +4 -0
- package/dist/runtime/components.js +48 -0
- package/dist/runtime/index.d.ts +3 -0
- package/dist/runtime/index.js +16 -0
- package/dist/sdk/client.d.ts +37 -0
- package/dist/sdk/client.js +413 -0
- package/dist/sdk/index.d.ts +4 -0
- package/dist/sdk/index.js +18 -0
- package/dist/sdk/types.d.ts +197 -0
- package/dist/sdk/types.js +2 -0
- package/dist/shared/artifact.d.ts +58 -0
- package/dist/shared/artifact.js +41 -0
- package/dist/shared/sanitize.d.ts +3 -0
- package/dist/shared/sanitize.js +48 -0
- package/package.json +57 -0
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createMotionGraphicsArtifact = exports.createRemotionStudioClient = exports.RemotionStudioError = void 0;
|
|
4
|
+
const artifact_1 = require("../shared/artifact");
|
|
5
|
+
Object.defineProperty(exports, "createMotionGraphicsArtifact", { enumerable: true, get: function () { return artifact_1.createMotionGraphicsArtifact; } });
|
|
6
|
+
const sanitize_1 = require("../shared/sanitize");
|
|
7
|
+
const sleep = async (ms, signal) => new Promise((resolve, reject) => {
|
|
8
|
+
const abortReason = signal?.reason ?? new DOMException("Aborted", "AbortError");
|
|
9
|
+
if (signal?.aborted) {
|
|
10
|
+
reject(abortReason);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const timeoutId = setTimeout(() => {
|
|
14
|
+
cleanup();
|
|
15
|
+
resolve();
|
|
16
|
+
}, ms);
|
|
17
|
+
const onAbort = () => {
|
|
18
|
+
clearTimeout(timeoutId);
|
|
19
|
+
cleanup();
|
|
20
|
+
reject(abortReason);
|
|
21
|
+
};
|
|
22
|
+
const cleanup = () => {
|
|
23
|
+
if (signal) {
|
|
24
|
+
signal.removeEventListener("abort", onAbort);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
if (signal) {
|
|
28
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
class RemotionStudioError extends Error {
|
|
32
|
+
constructor(data) {
|
|
33
|
+
super(data.message);
|
|
34
|
+
this.name = "RemotionStudioError";
|
|
35
|
+
this.type = data.type;
|
|
36
|
+
this.status = data.status;
|
|
37
|
+
this.failedEdit = data.failedEdit;
|
|
38
|
+
this.availableCredits = data.availableCredits;
|
|
39
|
+
this.requiredCredits = data.requiredCredits;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.RemotionStudioError = RemotionStudioError;
|
|
43
|
+
const mergeHeaders = (defaultHeaders, requestHeaders) => {
|
|
44
|
+
const headers = new Headers(defaultHeaders ?? {});
|
|
45
|
+
if (requestHeaders) {
|
|
46
|
+
const extraHeaders = new Headers(requestHeaders);
|
|
47
|
+
extraHeaders.forEach((value, key) => {
|
|
48
|
+
headers.set(key, value);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return headers;
|
|
52
|
+
};
|
|
53
|
+
const resolveUrl = (baseUrl, path) => {
|
|
54
|
+
if (!baseUrl) {
|
|
55
|
+
return path;
|
|
56
|
+
}
|
|
57
|
+
return new URL(path, baseUrl).toString();
|
|
58
|
+
};
|
|
59
|
+
const normalizeErrorType = (value) => {
|
|
60
|
+
if (value === "validation" ||
|
|
61
|
+
value === "edit_failed" ||
|
|
62
|
+
value === "authentication" ||
|
|
63
|
+
value === "authorization" ||
|
|
64
|
+
value === "insufficient_credits" ||
|
|
65
|
+
value === "billing_unavailable" ||
|
|
66
|
+
value === "not_found") {
|
|
67
|
+
return value;
|
|
68
|
+
}
|
|
69
|
+
return "api";
|
|
70
|
+
};
|
|
71
|
+
const parseErrorResponse = async (response) => {
|
|
72
|
+
const data = await response.json().catch(() => ({}));
|
|
73
|
+
const message = typeof data.error === "string"
|
|
74
|
+
? data.error
|
|
75
|
+
: typeof data.message === "string"
|
|
76
|
+
? data.message
|
|
77
|
+
: `API error: ${response.status}`;
|
|
78
|
+
throw new RemotionStudioError({
|
|
79
|
+
message,
|
|
80
|
+
type: normalizeErrorType(data.type === "error" && typeof data.errorType === "string"
|
|
81
|
+
? data.errorType
|
|
82
|
+
: data.type),
|
|
83
|
+
status: response.status,
|
|
84
|
+
failedEdit: data.failedEdit,
|
|
85
|
+
availableCredits: typeof data.availableCredits === "number"
|
|
86
|
+
? data.availableCredits
|
|
87
|
+
: undefined,
|
|
88
|
+
requiredCredits: typeof data.requiredCredits === "number"
|
|
89
|
+
? data.requiredCredits
|
|
90
|
+
: undefined,
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
const assertJsonResponse = async (response) => {
|
|
94
|
+
if (!response.ok) {
|
|
95
|
+
await parseErrorResponse(response);
|
|
96
|
+
}
|
|
97
|
+
const contentType = response.headers.get("content-type") || "";
|
|
98
|
+
if (!contentType.includes("application/json")) {
|
|
99
|
+
throw new RemotionStudioError({
|
|
100
|
+
message: "Expected a JSON response from the API.",
|
|
101
|
+
type: "api",
|
|
102
|
+
status: response.status,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return (await response.json());
|
|
106
|
+
};
|
|
107
|
+
const createPostRequest = async (fetchImpl, url, body, headers, signal) => {
|
|
108
|
+
const response = await fetchImpl(url, {
|
|
109
|
+
method: "POST",
|
|
110
|
+
headers,
|
|
111
|
+
body: JSON.stringify(body),
|
|
112
|
+
signal,
|
|
113
|
+
});
|
|
114
|
+
return assertJsonResponse(response);
|
|
115
|
+
};
|
|
116
|
+
const createGetRequest = async (fetchImpl, url, headers, signal) => {
|
|
117
|
+
const response = await fetchImpl(url, {
|
|
118
|
+
method: "GET",
|
|
119
|
+
headers,
|
|
120
|
+
signal,
|
|
121
|
+
});
|
|
122
|
+
return assertJsonResponse(response);
|
|
123
|
+
};
|
|
124
|
+
const createRemotionStudioClient = ({ baseUrl, fetch: providedFetch, headers: defaultHeaders, } = {}) => {
|
|
125
|
+
const fetchImpl = providedFetch ?? fetch;
|
|
126
|
+
const postJson = (path, body, options) => {
|
|
127
|
+
const headers = mergeHeaders(defaultHeaders, options?.headers);
|
|
128
|
+
if (!headers.has("Content-Type")) {
|
|
129
|
+
headers.set("Content-Type", "application/json");
|
|
130
|
+
}
|
|
131
|
+
return createPostRequest(fetchImpl, resolveUrl(baseUrl, path), body, headers, options?.signal);
|
|
132
|
+
};
|
|
133
|
+
const getJson = (path, options) => {
|
|
134
|
+
const headers = mergeHeaders(defaultHeaders, options?.headers);
|
|
135
|
+
return createGetRequest(fetchImpl, resolveUrl(baseUrl, path), headers, options?.signal);
|
|
136
|
+
};
|
|
137
|
+
const pollJob = async (path, jobLabel, options = {}) => {
|
|
138
|
+
const { headers, intervalMs = 2000, timeoutMs, signal, onUpdate, } = options;
|
|
139
|
+
const startedAt = Date.now();
|
|
140
|
+
while (true) {
|
|
141
|
+
if (timeoutMs != null && Date.now() - startedAt > timeoutMs) {
|
|
142
|
+
throw new RemotionStudioError({
|
|
143
|
+
message: `${jobLabel} did not complete within ${timeoutMs}ms.`,
|
|
144
|
+
type: "api",
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
const job = await getJson(path, { headers, signal });
|
|
148
|
+
onUpdate?.(job);
|
|
149
|
+
if (job.status === "completed" && job.result) {
|
|
150
|
+
return job.result;
|
|
151
|
+
}
|
|
152
|
+
if (job.status === "failed") {
|
|
153
|
+
throw new RemotionStudioError({
|
|
154
|
+
message: job.error?.message ??
|
|
155
|
+
`${jobLabel} failed without an error message.`,
|
|
156
|
+
type: job.error?.type ?? "api",
|
|
157
|
+
status: job.error?.status,
|
|
158
|
+
availableCredits: job.error?.availableCredits,
|
|
159
|
+
requiredCredits: job.error?.requiredCredits,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
await sleep(intervalMs, signal);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
const unwrapRenderEnvelope = async (response) => {
|
|
166
|
+
if (!response.ok) {
|
|
167
|
+
await parseErrorResponse(response);
|
|
168
|
+
}
|
|
169
|
+
const payload = await assertJsonResponse(response);
|
|
170
|
+
if (payload.type !== "success" || typeof payload.data === "undefined") {
|
|
171
|
+
throw new RemotionStudioError({
|
|
172
|
+
message: "Expected a successful render response from the API.",
|
|
173
|
+
type: "api",
|
|
174
|
+
status: response.status,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
return payload.data;
|
|
178
|
+
};
|
|
179
|
+
const postRenderJson = async (path, body, options) => {
|
|
180
|
+
const headers = mergeHeaders(defaultHeaders, options?.headers);
|
|
181
|
+
if (!headers.has("Content-Type")) {
|
|
182
|
+
headers.set("Content-Type", "application/json");
|
|
183
|
+
}
|
|
184
|
+
const response = await fetchImpl(resolveUrl(baseUrl, path), {
|
|
185
|
+
method: "POST",
|
|
186
|
+
headers,
|
|
187
|
+
body: JSON.stringify(body),
|
|
188
|
+
signal: options?.signal,
|
|
189
|
+
});
|
|
190
|
+
return unwrapRenderEnvelope(response);
|
|
191
|
+
};
|
|
192
|
+
return {
|
|
193
|
+
async generate(request, options) {
|
|
194
|
+
return postJson("/api/generate", {
|
|
195
|
+
...request,
|
|
196
|
+
streaming: false,
|
|
197
|
+
}, options);
|
|
198
|
+
},
|
|
199
|
+
async edit(request, options) {
|
|
200
|
+
return postJson("/api/edit", request, options);
|
|
201
|
+
},
|
|
202
|
+
async generateAsync(request, options) {
|
|
203
|
+
return postJson("/api/generate/async", request, options);
|
|
204
|
+
},
|
|
205
|
+
async editAsync(request, options) {
|
|
206
|
+
return postJson("/api/edit/async", request, options);
|
|
207
|
+
},
|
|
208
|
+
async getGenerationJob(jobId, options) {
|
|
209
|
+
return getJson(`/api/generate/async/${jobId}`, options);
|
|
210
|
+
},
|
|
211
|
+
async getEditJob(jobId, options) {
|
|
212
|
+
return getJson(`/api/edit/async/${jobId}`, options);
|
|
213
|
+
},
|
|
214
|
+
async pollGenerationJob(jobId, options = {}) {
|
|
215
|
+
return pollJob(`/api/generate/async/${jobId}`, `Generation job ${jobId}`, options);
|
|
216
|
+
},
|
|
217
|
+
async pollEditJob(jobId, options = {}) {
|
|
218
|
+
return pollJob(`/api/edit/async/${jobId}`, `Edit job ${jobId}`, options);
|
|
219
|
+
},
|
|
220
|
+
async render(request, options) {
|
|
221
|
+
return postRenderJson("/api/render/render", request, options);
|
|
222
|
+
},
|
|
223
|
+
async getRenderProgress(request, options) {
|
|
224
|
+
return postRenderJson("/api/render/progress", request, options);
|
|
225
|
+
},
|
|
226
|
+
async pollRenderProgress(request, options = {}) {
|
|
227
|
+
const { headers, intervalMs = 2000, timeoutMs, signal, onUpdate, } = options;
|
|
228
|
+
const startedAt = Date.now();
|
|
229
|
+
while (true) {
|
|
230
|
+
if (timeoutMs != null && Date.now() - startedAt > timeoutMs) {
|
|
231
|
+
throw new RemotionStudioError({
|
|
232
|
+
message: `Render ${request.id} did not complete within ${timeoutMs}ms.`,
|
|
233
|
+
type: "api",
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
const progress = await postRenderJson("/api/render/progress", request, { headers, signal });
|
|
237
|
+
onUpdate?.(progress);
|
|
238
|
+
if (progress.type === "done") {
|
|
239
|
+
return progress;
|
|
240
|
+
}
|
|
241
|
+
if (progress.type === "error") {
|
|
242
|
+
throw new RemotionStudioError({
|
|
243
|
+
message: progress.message,
|
|
244
|
+
type: "api",
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
await sleep(intervalMs, signal);
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
async generateStream(request, callbacks = {}, options) {
|
|
251
|
+
const headers = mergeHeaders(defaultHeaders, options?.headers);
|
|
252
|
+
if (!headers.has("Content-Type")) {
|
|
253
|
+
headers.set("Content-Type", "application/json");
|
|
254
|
+
}
|
|
255
|
+
const response = await fetchImpl(resolveUrl(baseUrl, "/api/generate"), {
|
|
256
|
+
method: "POST",
|
|
257
|
+
headers,
|
|
258
|
+
body: JSON.stringify({
|
|
259
|
+
...request,
|
|
260
|
+
streaming: true,
|
|
261
|
+
}),
|
|
262
|
+
});
|
|
263
|
+
if (!response.ok) {
|
|
264
|
+
await parseErrorResponse(response);
|
|
265
|
+
}
|
|
266
|
+
const contentType = response.headers.get("content-type") || "";
|
|
267
|
+
if (contentType.includes("application/json")) {
|
|
268
|
+
const data = await assertJsonResponse(response);
|
|
269
|
+
callbacks.onMetadata?.({
|
|
270
|
+
skills: data.metadata.skills,
|
|
271
|
+
model: data.metadata.model,
|
|
272
|
+
preset: data.metadata.preset,
|
|
273
|
+
});
|
|
274
|
+
callbacks.onCode?.(data.code);
|
|
275
|
+
return {
|
|
276
|
+
code: data.code,
|
|
277
|
+
reasoning: "",
|
|
278
|
+
metadata: {
|
|
279
|
+
skills: data.metadata.skills,
|
|
280
|
+
model: data.metadata.model,
|
|
281
|
+
preset: data.metadata.preset,
|
|
282
|
+
},
|
|
283
|
+
summary: data.summary,
|
|
284
|
+
artifact: data.artifact,
|
|
285
|
+
thread: data.thread,
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
const reader = response.body?.getReader();
|
|
289
|
+
if (!reader) {
|
|
290
|
+
throw new RemotionStudioError({
|
|
291
|
+
message: "No response body",
|
|
292
|
+
type: "api",
|
|
293
|
+
status: response.status,
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
const decoder = new TextDecoder();
|
|
297
|
+
let accumulatedText = "";
|
|
298
|
+
let reasoningText = "";
|
|
299
|
+
let buffer = "";
|
|
300
|
+
let streamMetadata = {};
|
|
301
|
+
let finalSummary;
|
|
302
|
+
let finalArtifact;
|
|
303
|
+
let finalThread;
|
|
304
|
+
while (true) {
|
|
305
|
+
const { done, value } = await reader.read();
|
|
306
|
+
if (done) {
|
|
307
|
+
break;
|
|
308
|
+
}
|
|
309
|
+
buffer += decoder.decode(value, { stream: true });
|
|
310
|
+
const lines = buffer.split("\n");
|
|
311
|
+
buffer = lines.pop() || "";
|
|
312
|
+
for (const line of lines) {
|
|
313
|
+
if (!line.startsWith("data:")) {
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
const data = line.slice(5).trimStart();
|
|
317
|
+
if (data === "[DONE]") {
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
try {
|
|
321
|
+
const event = JSON.parse(data);
|
|
322
|
+
if (event.type === "metadata") {
|
|
323
|
+
streamMetadata = {
|
|
324
|
+
skills: event.skills,
|
|
325
|
+
model: event.model,
|
|
326
|
+
preset: event.preset,
|
|
327
|
+
};
|
|
328
|
+
callbacks.onMetadata?.(streamMetadata);
|
|
329
|
+
}
|
|
330
|
+
else if (event.type === "reasoning-start") {
|
|
331
|
+
callbacks.onReasoningStart?.();
|
|
332
|
+
}
|
|
333
|
+
else if (event.type === "reasoning-delta" ||
|
|
334
|
+
event.type === "reasoning") {
|
|
335
|
+
const delta = String(event.delta ?? event.text ?? "");
|
|
336
|
+
if (!delta) {
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
reasoningText += delta;
|
|
340
|
+
callbacks.onReasoning?.(reasoningText);
|
|
341
|
+
}
|
|
342
|
+
else if (event.type === "text-start") {
|
|
343
|
+
callbacks.onTextStart?.();
|
|
344
|
+
}
|
|
345
|
+
else if (event.type === "text-delta" ||
|
|
346
|
+
event.type === "text" ||
|
|
347
|
+
event.type === "response.output_text.delta" ||
|
|
348
|
+
event.type === "output_text.delta") {
|
|
349
|
+
const delta = String(event.delta ?? event.text ?? "");
|
|
350
|
+
if (!delta) {
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
accumulatedText += delta;
|
|
354
|
+
callbacks.onCode?.((0, sanitize_1.stripMarkdownFences)(accumulatedText));
|
|
355
|
+
}
|
|
356
|
+
else if (event.type === "complete") {
|
|
357
|
+
if (typeof event.code === "string") {
|
|
358
|
+
accumulatedText = event.code;
|
|
359
|
+
}
|
|
360
|
+
finalSummary =
|
|
361
|
+
typeof event.summary === "string" ? event.summary : undefined;
|
|
362
|
+
finalArtifact = event.artifact;
|
|
363
|
+
finalThread = event.thread;
|
|
364
|
+
}
|
|
365
|
+
else if (event.type === "error") {
|
|
366
|
+
const streamError = typeof event.error === "string"
|
|
367
|
+
? event.error
|
|
368
|
+
: typeof event.error?.message === "string"
|
|
369
|
+
? event.error.message
|
|
370
|
+
: typeof event.message === "string"
|
|
371
|
+
? event.message
|
|
372
|
+
: typeof event.errorText === "string"
|
|
373
|
+
? event.errorText
|
|
374
|
+
: "Model stream returned an unknown error.";
|
|
375
|
+
throw new RemotionStudioError({
|
|
376
|
+
message: streamError,
|
|
377
|
+
type: normalizeErrorType(event.errorType ?? event.type),
|
|
378
|
+
availableCredits: typeof event.availableCredits === "number"
|
|
379
|
+
? event.availableCredits
|
|
380
|
+
: undefined,
|
|
381
|
+
requiredCredits: typeof event.requiredCredits === "number"
|
|
382
|
+
? event.requiredCredits
|
|
383
|
+
: undefined,
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
catch (error) {
|
|
388
|
+
if (error instanceof SyntaxError) {
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
throw error;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
const finalCode = (0, sanitize_1.extractComponentCode)((0, sanitize_1.stripMarkdownFences)(accumulatedText));
|
|
396
|
+
if (!finalCode.trim()) {
|
|
397
|
+
throw new RemotionStudioError({
|
|
398
|
+
message: "No code was returned by the model stream. Try a different model or prompt.",
|
|
399
|
+
type: "api",
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
return {
|
|
403
|
+
code: (0, sanitize_1.sanitizeGeneratedCode)(finalCode),
|
|
404
|
+
reasoning: reasoningText,
|
|
405
|
+
metadata: streamMetadata,
|
|
406
|
+
summary: finalSummary,
|
|
407
|
+
artifact: finalArtifact,
|
|
408
|
+
thread: finalThread,
|
|
409
|
+
};
|
|
410
|
+
},
|
|
411
|
+
};
|
|
412
|
+
};
|
|
413
|
+
exports.createRemotionStudioClient = createRemotionStudioClient;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { DEFAULT_MOTION_GRAPHICS_DURATION_IN_FRAMES, DEFAULT_MOTION_GRAPHICS_FPS, DEFAULT_MOTION_GRAPHICS_HEIGHT, DEFAULT_MOTION_GRAPHICS_WIDTH, MOTION_GRAPHICS_ARTIFACT_VERSION, MOTION_GRAPHICS_RUNTIME, createMotionGraphicsArtifact, type MotionGraphicsArtifact, type MotionGraphicsArtifactV1, type MotionGraphicsCompositionProps, type MotionGraphicsEditType, type MotionGraphicsPresetReference, } from "../shared/artifact";
|
|
2
|
+
export { extractComponentCode, sanitizeGeneratedCode, stripMarkdownFences, } from "../shared/sanitize";
|
|
3
|
+
export { RemotionStudioError, createRemotionStudioClient, } from "./client";
|
|
4
|
+
export type { AsyncWebhookCallback, ConversationContextMessage, EditAsyncRequest, EditJobAcceptedResponse, EditJobResponse, EditOperation, EditRequest, EditResponse, ErrorCorrectionContext, FailedEditInfo, GenerateAsyncRequest, GenerationJobAcceptedResponse, GenerationJobError, GenerationJobResponse, GenerationJobStatus, GenerationThreadSummary, PollEditJobOptions, PollRenderProgressOptions, PollGenerationJobOptions, RenderCompositionInput, RenderProgressRequest, RenderProgressResponse, RenderRequest, RenderResponse, GenerateRequest, GenerateResponse, GenerateStreamCallbacks, GenerateStreamMetadata, GenerateStreamResult, RemotionStudioErrorData, RemotionStudioErrorType, ResponseMetadata, } from "./types";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createRemotionStudioClient = exports.RemotionStudioError = exports.stripMarkdownFences = exports.sanitizeGeneratedCode = exports.extractComponentCode = exports.createMotionGraphicsArtifact = exports.MOTION_GRAPHICS_RUNTIME = exports.MOTION_GRAPHICS_ARTIFACT_VERSION = exports.DEFAULT_MOTION_GRAPHICS_WIDTH = exports.DEFAULT_MOTION_GRAPHICS_HEIGHT = exports.DEFAULT_MOTION_GRAPHICS_FPS = exports.DEFAULT_MOTION_GRAPHICS_DURATION_IN_FRAMES = void 0;
|
|
4
|
+
var artifact_1 = require("../shared/artifact");
|
|
5
|
+
Object.defineProperty(exports, "DEFAULT_MOTION_GRAPHICS_DURATION_IN_FRAMES", { enumerable: true, get: function () { return artifact_1.DEFAULT_MOTION_GRAPHICS_DURATION_IN_FRAMES; } });
|
|
6
|
+
Object.defineProperty(exports, "DEFAULT_MOTION_GRAPHICS_FPS", { enumerable: true, get: function () { return artifact_1.DEFAULT_MOTION_GRAPHICS_FPS; } });
|
|
7
|
+
Object.defineProperty(exports, "DEFAULT_MOTION_GRAPHICS_HEIGHT", { enumerable: true, get: function () { return artifact_1.DEFAULT_MOTION_GRAPHICS_HEIGHT; } });
|
|
8
|
+
Object.defineProperty(exports, "DEFAULT_MOTION_GRAPHICS_WIDTH", { enumerable: true, get: function () { return artifact_1.DEFAULT_MOTION_GRAPHICS_WIDTH; } });
|
|
9
|
+
Object.defineProperty(exports, "MOTION_GRAPHICS_ARTIFACT_VERSION", { enumerable: true, get: function () { return artifact_1.MOTION_GRAPHICS_ARTIFACT_VERSION; } });
|
|
10
|
+
Object.defineProperty(exports, "MOTION_GRAPHICS_RUNTIME", { enumerable: true, get: function () { return artifact_1.MOTION_GRAPHICS_RUNTIME; } });
|
|
11
|
+
Object.defineProperty(exports, "createMotionGraphicsArtifact", { enumerable: true, get: function () { return artifact_1.createMotionGraphicsArtifact; } });
|
|
12
|
+
var sanitize_1 = require("../shared/sanitize");
|
|
13
|
+
Object.defineProperty(exports, "extractComponentCode", { enumerable: true, get: function () { return sanitize_1.extractComponentCode; } });
|
|
14
|
+
Object.defineProperty(exports, "sanitizeGeneratedCode", { enumerable: true, get: function () { return sanitize_1.sanitizeGeneratedCode; } });
|
|
15
|
+
Object.defineProperty(exports, "stripMarkdownFences", { enumerable: true, get: function () { return sanitize_1.stripMarkdownFences; } });
|
|
16
|
+
var client_1 = require("./client");
|
|
17
|
+
Object.defineProperty(exports, "RemotionStudioError", { enumerable: true, get: function () { return client_1.RemotionStudioError; } });
|
|
18
|
+
Object.defineProperty(exports, "createRemotionStudioClient", { enumerable: true, get: function () { return client_1.createRemotionStudioClient; } });
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import type { MotionGraphicsArtifact, MotionGraphicsEditType, MotionGraphicsPresetReference } from "../shared/artifact";
|
|
2
|
+
export type EditOperation = {
|
|
3
|
+
description: string;
|
|
4
|
+
old_string: string;
|
|
5
|
+
new_string: string;
|
|
6
|
+
lineNumber?: number;
|
|
7
|
+
};
|
|
8
|
+
export type ConversationContextMessage = {
|
|
9
|
+
role: "user" | "assistant";
|
|
10
|
+
content: string;
|
|
11
|
+
attachedImages?: string[];
|
|
12
|
+
};
|
|
13
|
+
export type ErrorCorrectionContext = {
|
|
14
|
+
error: string;
|
|
15
|
+
source?: "compilation" | "runtime" | "generation";
|
|
16
|
+
attemptNumber: number;
|
|
17
|
+
maxAttempts: number;
|
|
18
|
+
failedEdit?: EditOperation;
|
|
19
|
+
};
|
|
20
|
+
export type AsyncWebhookCallback = {
|
|
21
|
+
url: string;
|
|
22
|
+
headers?: Record<string, string>;
|
|
23
|
+
};
|
|
24
|
+
export type RenderCompositionInput = {
|
|
25
|
+
code: string;
|
|
26
|
+
durationInFrames: number;
|
|
27
|
+
fps: number;
|
|
28
|
+
};
|
|
29
|
+
export type GenerateRequest = {
|
|
30
|
+
prompt: string;
|
|
31
|
+
presetId?: string;
|
|
32
|
+
model?: string;
|
|
33
|
+
reasoningEffort?: "none" | "low" | "medium" | "high" | "xhigh";
|
|
34
|
+
frameImages?: string[];
|
|
35
|
+
streaming?: boolean;
|
|
36
|
+
};
|
|
37
|
+
export type GenerateAsyncRequest = Omit<GenerateRequest, "streaming"> & {
|
|
38
|
+
webhook?: AsyncWebhookCallback;
|
|
39
|
+
};
|
|
40
|
+
export type EditRequest = {
|
|
41
|
+
prompt: string;
|
|
42
|
+
model?: string;
|
|
43
|
+
reasoningEffort?: "none" | "low" | "medium" | "high" | "xhigh";
|
|
44
|
+
currentCode: string;
|
|
45
|
+
threadId?: string;
|
|
46
|
+
conversationHistory?: ConversationContextMessage[];
|
|
47
|
+
hasManualEdits?: boolean;
|
|
48
|
+
errorCorrection?: ErrorCorrectionContext;
|
|
49
|
+
previouslyUsedSkills?: string[];
|
|
50
|
+
frameImages?: string[];
|
|
51
|
+
};
|
|
52
|
+
export type EditAsyncRequest = EditRequest & {
|
|
53
|
+
webhook?: AsyncWebhookCallback;
|
|
54
|
+
};
|
|
55
|
+
export type RenderRequest = {
|
|
56
|
+
inputProps: RenderCompositionInput;
|
|
57
|
+
threadId?: string;
|
|
58
|
+
};
|
|
59
|
+
export type RenderResponse = {
|
|
60
|
+
renderId: string;
|
|
61
|
+
bucketName: string;
|
|
62
|
+
cloudWatchLogs: string;
|
|
63
|
+
cloudWatchMainLogs: string;
|
|
64
|
+
lambdaInsightsLogs: string;
|
|
65
|
+
folderInS3Console: string;
|
|
66
|
+
progressJsonInConsole: string;
|
|
67
|
+
};
|
|
68
|
+
export type RenderProgressRequest = {
|
|
69
|
+
bucketName: string;
|
|
70
|
+
id: string;
|
|
71
|
+
};
|
|
72
|
+
export type RenderProgressResponse = {
|
|
73
|
+
type: "error";
|
|
74
|
+
message: string;
|
|
75
|
+
} | {
|
|
76
|
+
type: "progress";
|
|
77
|
+
progress: number;
|
|
78
|
+
} | {
|
|
79
|
+
type: "done";
|
|
80
|
+
url: string;
|
|
81
|
+
size: number;
|
|
82
|
+
};
|
|
83
|
+
export type PollRenderProgressOptions = {
|
|
84
|
+
headers?: HeadersInit;
|
|
85
|
+
intervalMs?: number;
|
|
86
|
+
timeoutMs?: number;
|
|
87
|
+
signal?: AbortSignal;
|
|
88
|
+
onUpdate?: (progress: RenderProgressResponse) => void;
|
|
89
|
+
};
|
|
90
|
+
export type ResponseMetadata = {
|
|
91
|
+
skills: string[];
|
|
92
|
+
editType: MotionGraphicsEditType;
|
|
93
|
+
edits?: EditOperation[];
|
|
94
|
+
model: string;
|
|
95
|
+
reasoning?: string;
|
|
96
|
+
preset?: MotionGraphicsPresetReference;
|
|
97
|
+
};
|
|
98
|
+
export type GenerationThreadSummary = {
|
|
99
|
+
id: string;
|
|
100
|
+
title: string;
|
|
101
|
+
messageCount: number;
|
|
102
|
+
updatedAt: string;
|
|
103
|
+
};
|
|
104
|
+
export type GenerateResponse = {
|
|
105
|
+
code: string;
|
|
106
|
+
summary: string;
|
|
107
|
+
metadata: ResponseMetadata;
|
|
108
|
+
artifact: MotionGraphicsArtifact;
|
|
109
|
+
thread?: GenerationThreadSummary;
|
|
110
|
+
};
|
|
111
|
+
export type GenerationJobStatus = "queued" | "processing" | "completed" | "failed";
|
|
112
|
+
export type GenerationJobError = {
|
|
113
|
+
message: string;
|
|
114
|
+
type: RemotionStudioErrorType;
|
|
115
|
+
status?: number;
|
|
116
|
+
availableCredits?: number;
|
|
117
|
+
requiredCredits?: number;
|
|
118
|
+
};
|
|
119
|
+
type QueuedJobAcceptedResponse<TRequestType extends "generate" | "edit"> = {
|
|
120
|
+
id: string;
|
|
121
|
+
requestType: TRequestType;
|
|
122
|
+
status: GenerationJobStatus;
|
|
123
|
+
createdAt: string;
|
|
124
|
+
pollUrl: string;
|
|
125
|
+
};
|
|
126
|
+
type QueuedJobResponse<TRequestType extends "generate" | "edit", TResult> = {
|
|
127
|
+
id: string;
|
|
128
|
+
requestType: TRequestType;
|
|
129
|
+
status: GenerationJobStatus;
|
|
130
|
+
createdAt: string;
|
|
131
|
+
startedAt?: string;
|
|
132
|
+
completedAt?: string;
|
|
133
|
+
pollUrl: string;
|
|
134
|
+
result?: TResult;
|
|
135
|
+
error?: GenerationJobError;
|
|
136
|
+
};
|
|
137
|
+
export type GenerationJobAcceptedResponse = QueuedJobAcceptedResponse<"generate">;
|
|
138
|
+
export type GenerationJobResponse = QueuedJobResponse<"generate", GenerateResponse>;
|
|
139
|
+
export type EditJobAcceptedResponse = QueuedJobAcceptedResponse<"edit">;
|
|
140
|
+
export type EditJobResponse = QueuedJobResponse<"edit", EditResponse>;
|
|
141
|
+
export type EditResponse = {
|
|
142
|
+
code: string;
|
|
143
|
+
summary: string;
|
|
144
|
+
metadata: ResponseMetadata;
|
|
145
|
+
artifact: MotionGraphicsArtifact;
|
|
146
|
+
thread?: GenerationThreadSummary;
|
|
147
|
+
};
|
|
148
|
+
export type FailedEditInfo = {
|
|
149
|
+
description: string;
|
|
150
|
+
old_string: string;
|
|
151
|
+
new_string: string;
|
|
152
|
+
lineNumber?: number;
|
|
153
|
+
};
|
|
154
|
+
export type RemotionStudioErrorType = "validation" | "api" | "edit_failed" | "authentication" | "authorization" | "insufficient_credits" | "billing_unavailable" | "not_found";
|
|
155
|
+
export type RemotionStudioErrorData = {
|
|
156
|
+
message: string;
|
|
157
|
+
type: RemotionStudioErrorType;
|
|
158
|
+
status?: number;
|
|
159
|
+
failedEdit?: FailedEditInfo;
|
|
160
|
+
availableCredits?: number;
|
|
161
|
+
requiredCredits?: number;
|
|
162
|
+
};
|
|
163
|
+
export type GenerateStreamMetadata = {
|
|
164
|
+
skills?: string[];
|
|
165
|
+
model?: string;
|
|
166
|
+
preset?: MotionGraphicsPresetReference;
|
|
167
|
+
};
|
|
168
|
+
export type GenerateStreamCallbacks = {
|
|
169
|
+
onMetadata?: (metadata: GenerateStreamMetadata) => void;
|
|
170
|
+
onReasoningStart?: () => void;
|
|
171
|
+
onReasoning?: (reasoning: string) => void;
|
|
172
|
+
onTextStart?: () => void;
|
|
173
|
+
onCode?: (partialCode: string) => void;
|
|
174
|
+
};
|
|
175
|
+
export type GenerateStreamResult = {
|
|
176
|
+
code: string;
|
|
177
|
+
reasoning: string;
|
|
178
|
+
metadata: GenerateStreamMetadata;
|
|
179
|
+
summary?: string;
|
|
180
|
+
artifact?: MotionGraphicsArtifact;
|
|
181
|
+
thread?: GenerationThreadSummary;
|
|
182
|
+
};
|
|
183
|
+
export type PollGenerationJobOptions = {
|
|
184
|
+
headers?: HeadersInit;
|
|
185
|
+
intervalMs?: number;
|
|
186
|
+
timeoutMs?: number;
|
|
187
|
+
signal?: AbortSignal;
|
|
188
|
+
onUpdate?: (job: GenerationJobResponse) => void;
|
|
189
|
+
};
|
|
190
|
+
export type PollEditJobOptions = {
|
|
191
|
+
headers?: HeadersInit;
|
|
192
|
+
intervalMs?: number;
|
|
193
|
+
timeoutMs?: number;
|
|
194
|
+
signal?: AbortSignal;
|
|
195
|
+
onUpdate?: (job: EditJobResponse) => void;
|
|
196
|
+
};
|
|
197
|
+
export {};
|