magic-hour 0.40.0 → 0.42.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 +10 -0
- package/dist/environment.d.ts +1 -1
- package/dist/environment.js +1 -1
- package/dist/resources/v1/ai-voice-generator/index.d.ts +2 -0
- package/dist/resources/v1/ai-voice-generator/index.js +5 -0
- package/dist/resources/v1/ai-voice-generator/request-types.d.ts +28 -0
- package/dist/resources/v1/ai-voice-generator/request-types.js +72 -0
- package/dist/resources/v1/ai-voice-generator/resource-client.d.ts +43 -0
- package/dist/resources/v1/ai-voice-generator/resource-client.js +90 -0
- package/dist/resources/v1/audio-projects/index.d.ts +2 -0
- package/dist/resources/v1/audio-projects/index.js +5 -0
- package/dist/resources/v1/audio-projects/request-types.d.ts +43 -0
- package/dist/resources/v1/audio-projects/request-types.js +96 -0
- package/dist/resources/v1/audio-projects/resource-client.d.ts +53 -0
- package/dist/resources/v1/audio-projects/resource-client.js +119 -0
- package/dist/resources/v1/audio-projects/resource-client.test.d.ts +1 -0
- package/dist/resources/v1/audio-projects/resource-client.test.js +552 -0
- package/dist/resources/v1/index.d.ts +2 -0
- package/dist/resources/v1/index.js +3 -1
- package/dist/resources/v1/lip-sync/request-types.d.ts +6 -0
- package/dist/resources/v1/lip-sync/request-types.js +5 -0
- package/dist/resources/v1/resource-client.d.ts +6 -0
- package/dist/resources/v1/resource-client.js +12 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/v1-ai-talking-photo-create-body-style-generation-mode-enum.d.ts +5 -3
- package/dist/types/v1-ai-talking-photo-create-body-style.d.ts +6 -4
- package/dist/types/v1-ai-talking-photo-create-body-style.js +6 -2
- package/dist/types/v1-ai-voice-generator-create-body-style-voice-name-enum.d.ts +4 -0
- package/dist/types/v1-ai-voice-generator-create-body-style-voice-name-enum.js +2 -0
- package/dist/types/v1-ai-voice-generator-create-body-style.d.ts +27 -0
- package/dist/types/v1-ai-voice-generator-create-body-style.js +93 -0
- package/dist/types/v1-ai-voice-generator-create-body.d.ts +28 -0
- package/dist/types/v1-ai-voice-generator-create-body.js +72 -0
- package/dist/types/v1-ai-voice-generator-create-response.d.ts +29 -0
- package/dist/types/v1-ai-voice-generator-create-response.js +71 -0
- package/dist/types/v1-audio-projects-get-response-downloads-item.d.ts +21 -0
- package/dist/types/v1-audio-projects-get-response-downloads-item.js +71 -0
- package/dist/types/v1-audio-projects-get-response-error.d.ts +27 -0
- package/dist/types/v1-audio-projects-get-response-error.js +71 -0
- package/dist/types/v1-audio-projects-get-response-status-enum.d.ts +4 -0
- package/dist/types/v1-audio-projects-get-response-status-enum.js +2 -0
- package/dist/types/v1-audio-projects-get-response.d.ts +60 -0
- package/dist/types/v1-audio-projects-get-response.js +115 -0
- package/dist/types/v1-lip-sync-create-body-style-generation-mode-enum.d.ts +10 -0
- package/dist/types/v1-lip-sync-create-body-style-generation-mode-enum.js +2 -0
- package/dist/types/v1-lip-sync-create-body-style.d.ts +28 -0
- package/dist/types/v1-lip-sync-create-body-style.js +67 -0
- package/dist/types/v1-lip-sync-create-body.d.ts +6 -0
- package/dist/types/v1-lip-sync-create-body.js +5 -0
- package/dist/types/v1-video-to-video-create-body-style-art-style-enum.d.ts +1 -1
- package/dist/types/v1-video-to-video-create-body-style.d.ts +10 -10
- package/dist/types/v1-video-to-video-create-body-style.js +16 -18
- package/package.json +1 -1
|
@@ -0,0 +1,552 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const magic_hour_1 = __importDefault(require("../../../index.js"));
|
|
16
|
+
const node_1 = require("msw/node");
|
|
17
|
+
const msw_1 = require("msw");
|
|
18
|
+
// Create MSW server
|
|
19
|
+
const server = (0, node_1.setupServer)();
|
|
20
|
+
// Mock the sleep helper
|
|
21
|
+
jest.mock("magic-hour/helpers/sleep", () => ({
|
|
22
|
+
sleep: jest.fn().mockResolvedValue(undefined),
|
|
23
|
+
}));
|
|
24
|
+
// Mock the download helper
|
|
25
|
+
jest.mock("magic-hour/helpers/download", () => ({
|
|
26
|
+
downloadFiles: jest.fn(),
|
|
27
|
+
}));
|
|
28
|
+
const { sleep } = require("../../../helpers/sleep");
|
|
29
|
+
const { downloadFiles } = require("../../../helpers/download");
|
|
30
|
+
describe("AudioProjectsClient.checkResult", () => {
|
|
31
|
+
let client;
|
|
32
|
+
beforeAll(() => {
|
|
33
|
+
// Start MSW server
|
|
34
|
+
server.listen();
|
|
35
|
+
});
|
|
36
|
+
afterAll(() => {
|
|
37
|
+
// Stop MSW server
|
|
38
|
+
server.close();
|
|
39
|
+
});
|
|
40
|
+
beforeEach(() => {
|
|
41
|
+
client = new magic_hour_1.default({
|
|
42
|
+
token: "API_TOKEN",
|
|
43
|
+
});
|
|
44
|
+
// Reset all mocks
|
|
45
|
+
jest.clearAllMocks();
|
|
46
|
+
// Reset MSW handlers
|
|
47
|
+
server.resetHandlers();
|
|
48
|
+
// Clean up environment variables
|
|
49
|
+
delete process.env["MAGIC_HOUR_POLL_INTERVAL"];
|
|
50
|
+
});
|
|
51
|
+
describe("Basic functionality", () => {
|
|
52
|
+
test("should return response without waiting when waitForCompletion is false", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
|
+
const mockResponse = {
|
|
54
|
+
id: "audio-123",
|
|
55
|
+
status: "rendering",
|
|
56
|
+
created_at: "2024-01-01T00:00:00Z",
|
|
57
|
+
credits_charged: 2,
|
|
58
|
+
downloads: [],
|
|
59
|
+
enabled: true,
|
|
60
|
+
error: null,
|
|
61
|
+
name: "Test Audio Project",
|
|
62
|
+
type: "VOICE_GENERATOR",
|
|
63
|
+
};
|
|
64
|
+
// Set up MSW handler for the API call
|
|
65
|
+
server.use(msw_1.http.get("https://api.magichour.ai/v1/audio-projects/audio-123", () => {
|
|
66
|
+
return msw_1.HttpResponse.json(mockResponse);
|
|
67
|
+
}));
|
|
68
|
+
const result = yield client.v1.audioProjects.checkResult({ id: "audio-123" }, { waitForCompletion: false });
|
|
69
|
+
expect(result).toEqual({
|
|
70
|
+
id: "audio-123",
|
|
71
|
+
status: "rendering",
|
|
72
|
+
createdAt: "2024-01-01T00:00:00Z",
|
|
73
|
+
creditsCharged: 2,
|
|
74
|
+
downloads: [],
|
|
75
|
+
enabled: true,
|
|
76
|
+
error: null,
|
|
77
|
+
name: "Test Audio Project",
|
|
78
|
+
type: "VOICE_GENERATOR",
|
|
79
|
+
});
|
|
80
|
+
expect(sleep).not.toHaveBeenCalled();
|
|
81
|
+
}));
|
|
82
|
+
test("should wait for completion and return successful result", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
83
|
+
const renderingResponse = {
|
|
84
|
+
id: "audio-123",
|
|
85
|
+
status: "rendering",
|
|
86
|
+
created_at: "2024-01-01T00:00:00Z",
|
|
87
|
+
credits_charged: 2,
|
|
88
|
+
downloads: [],
|
|
89
|
+
enabled: true,
|
|
90
|
+
error: null,
|
|
91
|
+
name: "Test Audio Project",
|
|
92
|
+
type: "VOICE_GENERATOR",
|
|
93
|
+
};
|
|
94
|
+
const completeResponse = {
|
|
95
|
+
id: "audio-123",
|
|
96
|
+
status: "complete",
|
|
97
|
+
created_at: "2024-01-01T00:00:00Z",
|
|
98
|
+
credits_charged: 2,
|
|
99
|
+
downloads: [
|
|
100
|
+
{
|
|
101
|
+
url: "https://example.com/download/audio1.wav",
|
|
102
|
+
expires_at: "2024-01-01T01:00:00Z",
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
enabled: true,
|
|
106
|
+
error: null,
|
|
107
|
+
name: "Test Audio Project",
|
|
108
|
+
type: "VOICE_GENERATOR",
|
|
109
|
+
};
|
|
110
|
+
let callCount = 0;
|
|
111
|
+
// Set up MSW handler that returns different responses on each call
|
|
112
|
+
server.use(msw_1.http.get("https://api.magichour.ai/v1/audio-projects/audio-123", () => {
|
|
113
|
+
callCount++;
|
|
114
|
+
if (callCount === 1) {
|
|
115
|
+
return msw_1.HttpResponse.json(renderingResponse);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
return msw_1.HttpResponse.json(completeResponse);
|
|
119
|
+
}
|
|
120
|
+
}));
|
|
121
|
+
downloadFiles.mockResolvedValue(["/tmp/audio1.wav"]);
|
|
122
|
+
const result = yield client.v1.audioProjects.checkResult({ id: "audio-123" }, {
|
|
123
|
+
waitForCompletion: true,
|
|
124
|
+
downloadOutputs: true,
|
|
125
|
+
downloadDirectory: "/tmp",
|
|
126
|
+
});
|
|
127
|
+
expect(result).toEqual({
|
|
128
|
+
id: "audio-123",
|
|
129
|
+
status: "complete",
|
|
130
|
+
createdAt: "2024-01-01T00:00:00Z",
|
|
131
|
+
creditsCharged: 2,
|
|
132
|
+
downloads: [
|
|
133
|
+
{
|
|
134
|
+
url: "https://example.com/download/audio1.wav",
|
|
135
|
+
expiresAt: "2024-01-01T01:00:00Z",
|
|
136
|
+
},
|
|
137
|
+
],
|
|
138
|
+
enabled: true,
|
|
139
|
+
error: null,
|
|
140
|
+
name: "Test Audio Project",
|
|
141
|
+
type: "VOICE_GENERATOR",
|
|
142
|
+
downloadedPaths: ["/tmp/audio1.wav"],
|
|
143
|
+
});
|
|
144
|
+
expect(sleep).toHaveBeenCalledWith(500); // Default poll interval
|
|
145
|
+
expect(downloadFiles).toHaveBeenCalledWith([
|
|
146
|
+
{
|
|
147
|
+
url: "https://example.com/download/audio1.wav",
|
|
148
|
+
expiresAt: "2024-01-01T01:00:00Z",
|
|
149
|
+
},
|
|
150
|
+
], "/tmp");
|
|
151
|
+
}));
|
|
152
|
+
test("should handle error status during polling", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
153
|
+
const renderingResponse = {
|
|
154
|
+
id: "audio-123",
|
|
155
|
+
status: "rendering",
|
|
156
|
+
created_at: "2024-01-01T00:00:00Z",
|
|
157
|
+
credits_charged: 2,
|
|
158
|
+
downloads: [],
|
|
159
|
+
enabled: true,
|
|
160
|
+
error: null,
|
|
161
|
+
name: "Test Audio Project",
|
|
162
|
+
type: "VOICE_GENERATOR",
|
|
163
|
+
};
|
|
164
|
+
const errorResponse = {
|
|
165
|
+
id: "audio-123",
|
|
166
|
+
status: "error",
|
|
167
|
+
created_at: "2024-01-01T00:00:00Z",
|
|
168
|
+
credits_charged: 2,
|
|
169
|
+
downloads: [],
|
|
170
|
+
enabled: true,
|
|
171
|
+
error: { message: "Rendering failed", code: "ERROR_001" },
|
|
172
|
+
name: "Test Audio Project",
|
|
173
|
+
type: "VOICE_GENERATOR",
|
|
174
|
+
};
|
|
175
|
+
let callCount = 0;
|
|
176
|
+
// Set up MSW handler that returns different responses on each call
|
|
177
|
+
server.use(msw_1.http.get("https://api.magichour.ai/v1/audio-projects/audio-123", () => {
|
|
178
|
+
callCount++;
|
|
179
|
+
if (callCount === 1) {
|
|
180
|
+
return msw_1.HttpResponse.json(renderingResponse);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
return msw_1.HttpResponse.json(errorResponse);
|
|
184
|
+
}
|
|
185
|
+
}));
|
|
186
|
+
const result = yield client.v1.audioProjects.checkResult({ id: "audio-123" }, { waitForCompletion: true });
|
|
187
|
+
expect(result).toEqual({
|
|
188
|
+
id: "audio-123",
|
|
189
|
+
status: "error",
|
|
190
|
+
createdAt: "2024-01-01T00:00:00Z",
|
|
191
|
+
creditsCharged: 2,
|
|
192
|
+
downloads: [],
|
|
193
|
+
enabled: true,
|
|
194
|
+
error: { message: "Rendering failed", code: "ERROR_001" },
|
|
195
|
+
name: "Test Audio Project",
|
|
196
|
+
type: "VOICE_GENERATOR",
|
|
197
|
+
});
|
|
198
|
+
}));
|
|
199
|
+
test("should handle canceled status during polling", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
200
|
+
const renderingResponse = {
|
|
201
|
+
id: "audio-123",
|
|
202
|
+
status: "rendering",
|
|
203
|
+
created_at: "2024-01-01T00:00:00Z",
|
|
204
|
+
credits_charged: 2,
|
|
205
|
+
downloads: [],
|
|
206
|
+
enabled: true,
|
|
207
|
+
error: null,
|
|
208
|
+
name: "Test Audio Project",
|
|
209
|
+
type: "VOICE_GENERATOR",
|
|
210
|
+
};
|
|
211
|
+
const canceledResponse = {
|
|
212
|
+
id: "audio-123",
|
|
213
|
+
status: "canceled",
|
|
214
|
+
created_at: "2024-01-01T00:00:00Z",
|
|
215
|
+
credits_charged: 2,
|
|
216
|
+
downloads: [],
|
|
217
|
+
enabled: true,
|
|
218
|
+
error: null,
|
|
219
|
+
name: "Test Audio Project",
|
|
220
|
+
type: "VOICE_GENERATOR",
|
|
221
|
+
};
|
|
222
|
+
let callCount = 0;
|
|
223
|
+
// Set up MSW handler that returns different responses on each call
|
|
224
|
+
server.use(msw_1.http.get("https://api.magichour.ai/v1/audio-projects/audio-123", () => {
|
|
225
|
+
callCount++;
|
|
226
|
+
if (callCount === 1) {
|
|
227
|
+
return msw_1.HttpResponse.json(renderingResponse);
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
return msw_1.HttpResponse.json(canceledResponse);
|
|
231
|
+
}
|
|
232
|
+
}));
|
|
233
|
+
const result = yield client.v1.audioProjects.checkResult({ id: "audio-123" }, { waitForCompletion: true });
|
|
234
|
+
expect(result).toEqual({
|
|
235
|
+
id: "audio-123",
|
|
236
|
+
status: "canceled",
|
|
237
|
+
createdAt: "2024-01-01T00:00:00Z",
|
|
238
|
+
creditsCharged: 2,
|
|
239
|
+
downloads: [],
|
|
240
|
+
enabled: true,
|
|
241
|
+
error: null,
|
|
242
|
+
name: "Test Audio Project",
|
|
243
|
+
type: "VOICE_GENERATOR",
|
|
244
|
+
});
|
|
245
|
+
}));
|
|
246
|
+
});
|
|
247
|
+
describe("Polling behavior", () => {
|
|
248
|
+
test("should use custom poll interval from environment", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
249
|
+
const renderingResponse = {
|
|
250
|
+
id: "audio-123",
|
|
251
|
+
status: "rendering",
|
|
252
|
+
created_at: "2024-01-01T00:00:00Z",
|
|
253
|
+
credits_charged: 2,
|
|
254
|
+
downloads: [],
|
|
255
|
+
enabled: true,
|
|
256
|
+
error: null,
|
|
257
|
+
name: "Test Audio Project",
|
|
258
|
+
type: "VOICE_GENERATOR",
|
|
259
|
+
};
|
|
260
|
+
const completeResponse = {
|
|
261
|
+
id: "audio-123",
|
|
262
|
+
status: "complete",
|
|
263
|
+
created_at: "2024-01-01T00:00:00Z",
|
|
264
|
+
credits_charged: 2,
|
|
265
|
+
downloads: [],
|
|
266
|
+
enabled: true,
|
|
267
|
+
error: null,
|
|
268
|
+
name: "Test Audio Project",
|
|
269
|
+
type: "VOICE_GENERATOR",
|
|
270
|
+
};
|
|
271
|
+
let callCount = 0;
|
|
272
|
+
// Set up MSW handler that returns different responses on each call
|
|
273
|
+
server.use(msw_1.http.get("https://api.magichour.ai/v1/audio-projects/audio-123", () => {
|
|
274
|
+
callCount++;
|
|
275
|
+
if (callCount === 1) {
|
|
276
|
+
return msw_1.HttpResponse.json(renderingResponse);
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
return msw_1.HttpResponse.json(completeResponse);
|
|
280
|
+
}
|
|
281
|
+
}));
|
|
282
|
+
// Set environment variable before the checkResult call
|
|
283
|
+
process.env["MAGIC_HOUR_POLL_INTERVAL"] = "1.5";
|
|
284
|
+
try {
|
|
285
|
+
yield client.v1.audioProjects.checkResult({ id: "audio-123" });
|
|
286
|
+
expect(sleep).toHaveBeenCalledWith(1500); // 1.5 seconds converted to milliseconds
|
|
287
|
+
}
|
|
288
|
+
finally {
|
|
289
|
+
// Clean up environment variable
|
|
290
|
+
delete process.env["MAGIC_HOUR_POLL_INTERVAL"];
|
|
291
|
+
}
|
|
292
|
+
}));
|
|
293
|
+
test("should poll multiple times until completion", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
294
|
+
const renderingResponse = {
|
|
295
|
+
id: "audio-123",
|
|
296
|
+
status: "rendering",
|
|
297
|
+
created_at: "2024-01-01T00:00:00Z",
|
|
298
|
+
credits_charged: 2,
|
|
299
|
+
downloads: [],
|
|
300
|
+
enabled: true,
|
|
301
|
+
error: null,
|
|
302
|
+
name: "Test Audio Project",
|
|
303
|
+
type: "VOICE_GENERATOR",
|
|
304
|
+
};
|
|
305
|
+
const queuedResponse = Object.assign(Object.assign({}, renderingResponse), { status: "queued" });
|
|
306
|
+
const completeResponse = Object.assign(Object.assign({}, renderingResponse), { status: "complete" });
|
|
307
|
+
let callCount = 0;
|
|
308
|
+
// Set up MSW handler that returns different responses on each call
|
|
309
|
+
server.use(msw_1.http.get("https://api.magichour.ai/v1/audio-projects/audio-123", () => {
|
|
310
|
+
callCount++;
|
|
311
|
+
if (callCount === 1) {
|
|
312
|
+
return msw_1.HttpResponse.json(renderingResponse);
|
|
313
|
+
}
|
|
314
|
+
else if (callCount === 2) {
|
|
315
|
+
return msw_1.HttpResponse.json(queuedResponse);
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
return msw_1.HttpResponse.json(completeResponse);
|
|
319
|
+
}
|
|
320
|
+
}));
|
|
321
|
+
yield client.v1.audioProjects.checkResult({ id: "audio-123" });
|
|
322
|
+
expect(sleep).toHaveBeenCalledTimes(2);
|
|
323
|
+
}));
|
|
324
|
+
});
|
|
325
|
+
describe("Download functionality", () => {
|
|
326
|
+
test("should skip download when downloadOutputs is false", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
327
|
+
const completeResponse = {
|
|
328
|
+
id: "audio-123",
|
|
329
|
+
status: "complete",
|
|
330
|
+
created_at: "2024-01-01T00:00:00Z",
|
|
331
|
+
credits_charged: 2,
|
|
332
|
+
downloads: [
|
|
333
|
+
{
|
|
334
|
+
url: "https://example.com/download/audio1.wav",
|
|
335
|
+
expires_at: "2024-01-01T01:00:00Z",
|
|
336
|
+
},
|
|
337
|
+
],
|
|
338
|
+
enabled: true,
|
|
339
|
+
error: null,
|
|
340
|
+
name: "Test Audio Project",
|
|
341
|
+
type: "VOICE_GENERATOR",
|
|
342
|
+
};
|
|
343
|
+
// Set up MSW handler
|
|
344
|
+
server.use(msw_1.http.get("https://api.magichour.ai/v1/audio-projects/audio-123", () => {
|
|
345
|
+
return msw_1.HttpResponse.json(completeResponse);
|
|
346
|
+
}));
|
|
347
|
+
const result = yield client.v1.audioProjects.checkResult({ id: "audio-123" }, {
|
|
348
|
+
waitForCompletion: true,
|
|
349
|
+
downloadOutputs: false,
|
|
350
|
+
});
|
|
351
|
+
expect(result).toEqual({
|
|
352
|
+
id: "audio-123",
|
|
353
|
+
status: "complete",
|
|
354
|
+
createdAt: "2024-01-01T00:00:00Z",
|
|
355
|
+
creditsCharged: 2,
|
|
356
|
+
downloads: [
|
|
357
|
+
{
|
|
358
|
+
url: "https://example.com/download/audio1.wav",
|
|
359
|
+
expiresAt: "2024-01-01T01:00:00Z",
|
|
360
|
+
},
|
|
361
|
+
],
|
|
362
|
+
enabled: true,
|
|
363
|
+
error: null,
|
|
364
|
+
name: "Test Audio Project",
|
|
365
|
+
type: "VOICE_GENERATOR",
|
|
366
|
+
});
|
|
367
|
+
expect(downloadFiles).not.toHaveBeenCalled();
|
|
368
|
+
}));
|
|
369
|
+
test("should download files to current directory when no downloadDirectory specified", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
370
|
+
const completeResponse = {
|
|
371
|
+
id: "audio-123",
|
|
372
|
+
status: "complete",
|
|
373
|
+
created_at: "2024-01-01T00:00:00Z",
|
|
374
|
+
credits_charged: 2,
|
|
375
|
+
downloads: [
|
|
376
|
+
{
|
|
377
|
+
url: "https://example.com/download/audio1.wav",
|
|
378
|
+
expires_at: "2024-01-01T01:00:00Z",
|
|
379
|
+
},
|
|
380
|
+
],
|
|
381
|
+
enabled: true,
|
|
382
|
+
error: null,
|
|
383
|
+
name: "Test Audio Project",
|
|
384
|
+
type: "VOICE_GENERATOR",
|
|
385
|
+
};
|
|
386
|
+
// Set up MSW handler
|
|
387
|
+
server.use(msw_1.http.get("https://api.magichour.ai/v1/audio-projects/audio-123", () => {
|
|
388
|
+
return msw_1.HttpResponse.json(completeResponse);
|
|
389
|
+
}));
|
|
390
|
+
downloadFiles.mockResolvedValue(["/current/dir/audio1.wav"]);
|
|
391
|
+
const result = yield client.v1.audioProjects.checkResult({ id: "audio-123" }, { downloadOutputs: true });
|
|
392
|
+
expect(downloadFiles).toHaveBeenCalledWith([
|
|
393
|
+
{
|
|
394
|
+
url: "https://example.com/download/audio1.wav",
|
|
395
|
+
expiresAt: "2024-01-01T01:00:00Z",
|
|
396
|
+
},
|
|
397
|
+
], undefined);
|
|
398
|
+
expect(result.downloadedPaths).toEqual(["/current/dir/audio1.wav"]);
|
|
399
|
+
}));
|
|
400
|
+
test("should handle download errors gracefully", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
401
|
+
const completeResponse = {
|
|
402
|
+
id: "audio-123",
|
|
403
|
+
status: "complete",
|
|
404
|
+
created_at: "2024-01-01T00:00:00Z",
|
|
405
|
+
credits_charged: 2,
|
|
406
|
+
downloads: [
|
|
407
|
+
{
|
|
408
|
+
url: "https://example.com/download/audio1.wav",
|
|
409
|
+
expires_at: "2024-01-01T01:00:00Z",
|
|
410
|
+
},
|
|
411
|
+
],
|
|
412
|
+
enabled: true,
|
|
413
|
+
error: null,
|
|
414
|
+
name: "Test Audio Project",
|
|
415
|
+
type: "VOICE_GENERATOR",
|
|
416
|
+
};
|
|
417
|
+
// Set up MSW handler
|
|
418
|
+
server.use(msw_1.http.get("https://api.magichour.ai/v1/audio-projects/audio-123", () => {
|
|
419
|
+
return msw_1.HttpResponse.json(completeResponse);
|
|
420
|
+
}));
|
|
421
|
+
downloadFiles.mockRejectedValue(new Error("Download failed"));
|
|
422
|
+
yield expect(client.v1.audioProjects.checkResult({ id: "audio-123" }, { downloadOutputs: true })).rejects.toThrow("Download failed");
|
|
423
|
+
}));
|
|
424
|
+
});
|
|
425
|
+
describe("Default behavior", () => {
|
|
426
|
+
test("should use default options when no options provided", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
427
|
+
const completeResponse = {
|
|
428
|
+
id: "audio-123",
|
|
429
|
+
status: "complete",
|
|
430
|
+
created_at: "2024-01-01T00:00:00Z",
|
|
431
|
+
credits_charged: 2,
|
|
432
|
+
downloads: [
|
|
433
|
+
{
|
|
434
|
+
url: "https://example.com/download/audio1.wav",
|
|
435
|
+
expires_at: "2024-01-01T01:00:00Z",
|
|
436
|
+
},
|
|
437
|
+
],
|
|
438
|
+
enabled: true,
|
|
439
|
+
error: null,
|
|
440
|
+
name: "Test Audio Project",
|
|
441
|
+
type: "VOICE_GENERATOR",
|
|
442
|
+
};
|
|
443
|
+
const renderingResponse = Object.assign(Object.assign({}, completeResponse), { status: "rendering" });
|
|
444
|
+
let callCount = 0;
|
|
445
|
+
// Set up MSW handler that returns different responses on each call
|
|
446
|
+
server.use(msw_1.http.get("https://api.magichour.ai/v1/audio-projects/audio-123", () => {
|
|
447
|
+
callCount++;
|
|
448
|
+
if (callCount === 1) {
|
|
449
|
+
return msw_1.HttpResponse.json(renderingResponse);
|
|
450
|
+
}
|
|
451
|
+
else {
|
|
452
|
+
return msw_1.HttpResponse.json(completeResponse);
|
|
453
|
+
}
|
|
454
|
+
}));
|
|
455
|
+
downloadFiles.mockResolvedValue(["/tmp/audio1.wav"]);
|
|
456
|
+
const result = yield client.v1.audioProjects.checkResult({
|
|
457
|
+
id: "audio-123",
|
|
458
|
+
});
|
|
459
|
+
expect(result.downloadedPaths).toEqual(["/tmp/audio1.wav"]);
|
|
460
|
+
expect(sleep).toHaveBeenCalledWith(500); // Default poll interval
|
|
461
|
+
}));
|
|
462
|
+
});
|
|
463
|
+
describe("Request options", () => {
|
|
464
|
+
test("should pass additional request options to get method", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
465
|
+
const mockResponse = {
|
|
466
|
+
id: "audio-123",
|
|
467
|
+
status: "complete",
|
|
468
|
+
created_at: "2024-01-01T00:00:00Z",
|
|
469
|
+
credits_charged: 2,
|
|
470
|
+
downloads: [],
|
|
471
|
+
enabled: true,
|
|
472
|
+
error: null,
|
|
473
|
+
name: "Test Audio Project",
|
|
474
|
+
type: "VOICE_GENERATOR",
|
|
475
|
+
};
|
|
476
|
+
// Set up MSW handler
|
|
477
|
+
server.use(msw_1.http.get("https://api.magichour.ai/v1/audio-projects/audio-123", () => {
|
|
478
|
+
return msw_1.HttpResponse.json(mockResponse);
|
|
479
|
+
}));
|
|
480
|
+
const getMock = jest.spyOn(client.v1.audioProjects, "get");
|
|
481
|
+
yield client.v1.audioProjects.checkResult({ id: "audio-123" }, {
|
|
482
|
+
waitForCompletion: false,
|
|
483
|
+
timeout: 30000,
|
|
484
|
+
});
|
|
485
|
+
expect(getMock).toHaveBeenCalledWith({ id: "audio-123" }, {
|
|
486
|
+
timeout: 30000,
|
|
487
|
+
});
|
|
488
|
+
}));
|
|
489
|
+
});
|
|
490
|
+
describe("Edge cases", () => {
|
|
491
|
+
test("should handle immediate completion without polling", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
492
|
+
const completeResponse = {
|
|
493
|
+
id: "audio-123",
|
|
494
|
+
status: "complete",
|
|
495
|
+
created_at: "2024-01-01T00:00:00Z",
|
|
496
|
+
credits_charged: 2,
|
|
497
|
+
downloads: [],
|
|
498
|
+
enabled: true,
|
|
499
|
+
error: null,
|
|
500
|
+
name: "Test Audio Project",
|
|
501
|
+
type: "VOICE_GENERATOR",
|
|
502
|
+
};
|
|
503
|
+
// Set up MSW handler
|
|
504
|
+
server.use(msw_1.http.get("https://api.magichour.ai/v1/audio-projects/audio-123", () => {
|
|
505
|
+
return msw_1.HttpResponse.json(completeResponse);
|
|
506
|
+
}));
|
|
507
|
+
const result = yield client.v1.audioProjects.checkResult({ id: "audio-123" }, { waitForCompletion: false });
|
|
508
|
+
expect(result).toEqual({
|
|
509
|
+
id: "audio-123",
|
|
510
|
+
status: "complete",
|
|
511
|
+
createdAt: "2024-01-01T00:00:00Z",
|
|
512
|
+
creditsCharged: 2,
|
|
513
|
+
downloads: [],
|
|
514
|
+
enabled: true,
|
|
515
|
+
error: null,
|
|
516
|
+
name: "Test Audio Project",
|
|
517
|
+
type: "VOICE_GENERATOR",
|
|
518
|
+
});
|
|
519
|
+
expect(sleep).not.toHaveBeenCalled();
|
|
520
|
+
expect(downloadFiles).not.toHaveBeenCalled();
|
|
521
|
+
}));
|
|
522
|
+
test("should handle empty downloads array", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
523
|
+
const completeResponse = {
|
|
524
|
+
id: "audio-123",
|
|
525
|
+
status: "complete",
|
|
526
|
+
created_at: "2024-01-01T00:00:00Z",
|
|
527
|
+
credits_charged: 2,
|
|
528
|
+
downloads: [],
|
|
529
|
+
enabled: true,
|
|
530
|
+
error: null,
|
|
531
|
+
name: "Test Audio Project",
|
|
532
|
+
type: "VOICE_GENERATOR",
|
|
533
|
+
};
|
|
534
|
+
// Set up MSW handler
|
|
535
|
+
server.use(msw_1.http.get("https://api.magichour.ai/v1/audio-projects/audio-123", () => {
|
|
536
|
+
return msw_1.HttpResponse.json(completeResponse);
|
|
537
|
+
}));
|
|
538
|
+
downloadFiles.mockResolvedValue([]);
|
|
539
|
+
const result = yield client.v1.audioProjects.checkResult({ id: "audio-123" }, { downloadOutputs: true });
|
|
540
|
+
expect(result.downloadedPaths).toEqual([]);
|
|
541
|
+
expect(downloadFiles).toHaveBeenCalledWith([], undefined);
|
|
542
|
+
}));
|
|
543
|
+
test("should handle get method throwing error", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
544
|
+
const error = new Error("API Error");
|
|
545
|
+
// Set up MSW handler that returns an error
|
|
546
|
+
server.use(msw_1.http.get("https://api.magichour.ai/v1/audio-projects/audio-123", () => {
|
|
547
|
+
return msw_1.HttpResponse.json({ error: "API Error" }, { status: 500 });
|
|
548
|
+
}));
|
|
549
|
+
yield expect(client.v1.audioProjects.checkResult({ id: "audio-123" })).rejects.toThrow();
|
|
550
|
+
}));
|
|
551
|
+
});
|
|
552
|
+
});
|
|
@@ -9,7 +9,9 @@ export * as aiMemeGenerator from "./ai-meme-generator";
|
|
|
9
9
|
export * as aiPhotoEditor from "./ai-photo-editor";
|
|
10
10
|
export * as aiQrCodeGenerator from "./ai-qr-code-generator";
|
|
11
11
|
export * as aiTalkingPhoto from "./ai-talking-photo";
|
|
12
|
+
export * as aiVoiceGenerator from "./ai-voice-generator";
|
|
12
13
|
export * as animation from "./animation";
|
|
14
|
+
export * as audioProjects from "./audio-projects";
|
|
13
15
|
export * as autoSubtitleGenerator from "./auto-subtitle-generator";
|
|
14
16
|
export * as faceDetection from "./face-detection";
|
|
15
17
|
export * as faceSwap from "./face-swap";
|
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.videoToVideo = exports.videoProjects = exports.textToVideo = exports.V1Client = exports.photoColorizer = exports.lipSync = exports.imageToVideo = exports.imageProjects = exports.imageBackgroundRemover = exports.files = exports.faceSwapPhoto = exports.faceSwap = exports.faceDetection = exports.autoSubtitleGenerator = exports.animation = exports.aiTalkingPhoto = exports.aiQrCodeGenerator = exports.aiPhotoEditor = exports.aiMemeGenerator = exports.aiImageUpscaler = exports.aiImageGenerator = exports.aiImageEditor = exports.aiHeadshotGenerator = exports.aiGifGenerator = exports.aiFaceEditor = exports.aiClothesChanger = void 0;
|
|
36
|
+
exports.videoToVideo = exports.videoProjects = exports.textToVideo = exports.V1Client = exports.photoColorizer = exports.lipSync = exports.imageToVideo = exports.imageProjects = exports.imageBackgroundRemover = exports.files = exports.faceSwapPhoto = exports.faceSwap = exports.faceDetection = exports.autoSubtitleGenerator = exports.audioProjects = exports.animation = exports.aiVoiceGenerator = exports.aiTalkingPhoto = exports.aiQrCodeGenerator = exports.aiPhotoEditor = exports.aiMemeGenerator = exports.aiImageUpscaler = exports.aiImageGenerator = exports.aiImageEditor = exports.aiHeadshotGenerator = exports.aiGifGenerator = exports.aiFaceEditor = exports.aiClothesChanger = void 0;
|
|
37
37
|
exports.aiClothesChanger = __importStar(require("./ai-clothes-changer"));
|
|
38
38
|
exports.aiFaceEditor = __importStar(require("./ai-face-editor"));
|
|
39
39
|
exports.aiGifGenerator = __importStar(require("./ai-gif-generator"));
|
|
@@ -45,7 +45,9 @@ exports.aiMemeGenerator = __importStar(require("./ai-meme-generator"));
|
|
|
45
45
|
exports.aiPhotoEditor = __importStar(require("./ai-photo-editor"));
|
|
46
46
|
exports.aiQrCodeGenerator = __importStar(require("./ai-qr-code-generator"));
|
|
47
47
|
exports.aiTalkingPhoto = __importStar(require("./ai-talking-photo"));
|
|
48
|
+
exports.aiVoiceGenerator = __importStar(require("./ai-voice-generator"));
|
|
48
49
|
exports.animation = __importStar(require("./animation"));
|
|
50
|
+
exports.audioProjects = __importStar(require("./audio-projects"));
|
|
49
51
|
exports.autoSubtitleGenerator = __importStar(require("./auto-subtitle-generator"));
|
|
50
52
|
exports.faceDetection = __importStar(require("./face-detection"));
|
|
51
53
|
exports.faceSwap = __importStar(require("./face-swap"));
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as z from "zod";
|
|
2
2
|
import { External$V1LipSyncCreateBodyAssets, V1LipSyncCreateBodyAssets } from "../../../types/v1-lip-sync-create-body-assets";
|
|
3
|
+
import { External$V1LipSyncCreateBodyStyle, V1LipSyncCreateBodyStyle } from "../../../types/v1-lip-sync-create-body-style";
|
|
3
4
|
/**
|
|
4
5
|
* CreateRequest
|
|
5
6
|
*/
|
|
@@ -34,6 +35,10 @@ export type CreateRequest = {
|
|
|
34
35
|
* The start time of the input video in seconds. This value is used to trim the input video. The value must be greater than 0.
|
|
35
36
|
*/
|
|
36
37
|
startSeconds: number;
|
|
38
|
+
/**
|
|
39
|
+
* Attributes used to dictate the style of the output
|
|
40
|
+
*/
|
|
41
|
+
style?: V1LipSyncCreateBodyStyle | undefined;
|
|
37
42
|
/**
|
|
38
43
|
* `width` is deprecated and no longer influences the output video's resolution.
|
|
39
44
|
*
|
|
@@ -57,6 +62,7 @@ export type External$CreateRequest = {
|
|
|
57
62
|
max_fps_limit?: number | undefined;
|
|
58
63
|
name?: string | undefined;
|
|
59
64
|
start_seconds: number;
|
|
65
|
+
style?: External$V1LipSyncCreateBodyStyle | undefined;
|
|
60
66
|
width?: number | null | undefined;
|
|
61
67
|
};
|
|
62
68
|
export declare const Schemas$CreateRequest: {
|
|
@@ -37,6 +37,7 @@ exports.Schemas$CreateRequest = void 0;
|
|
|
37
37
|
const make_api_request_js_1 = require("make-api-request-js");
|
|
38
38
|
const z = __importStar(require("zod"));
|
|
39
39
|
const v1_lip_sync_create_body_assets_1 = require("../../../types/v1-lip-sync-create-body-assets");
|
|
40
|
+
const v1_lip_sync_create_body_style_1 = require("../../../types/v1-lip-sync-create-body-style");
|
|
40
41
|
/**
|
|
41
42
|
* Takes network data, validates it, and transforms keys to match typescript object CreateRequest
|
|
42
43
|
*/
|
|
@@ -48,6 +49,7 @@ const SchemaIn$CreateRequest = z
|
|
|
48
49
|
max_fps_limit: z.number().optional(),
|
|
49
50
|
name: z.string().optional(),
|
|
50
51
|
start_seconds: z.number(),
|
|
52
|
+
style: v1_lip_sync_create_body_style_1.Schemas$V1LipSyncCreateBodyStyle.in.optional(),
|
|
51
53
|
width: z.number().int().nullable().optional(),
|
|
52
54
|
})
|
|
53
55
|
.transform((obj) => {
|
|
@@ -58,6 +60,7 @@ const SchemaIn$CreateRequest = z
|
|
|
58
60
|
max_fps_limit: "maxFpsLimit",
|
|
59
61
|
name: "name",
|
|
60
62
|
start_seconds: "startSeconds",
|
|
63
|
+
style: "style",
|
|
61
64
|
width: "width",
|
|
62
65
|
});
|
|
63
66
|
});
|
|
@@ -73,6 +76,7 @@ const SchemaOut$CreateRequest = z
|
|
|
73
76
|
maxFpsLimit: z.number().optional(),
|
|
74
77
|
name: z.string().optional(),
|
|
75
78
|
startSeconds: z.number(),
|
|
79
|
+
style: v1_lip_sync_create_body_style_1.Schemas$V1LipSyncCreateBodyStyle.out.optional(),
|
|
76
80
|
width: z.number().int().nullable().optional(),
|
|
77
81
|
})
|
|
78
82
|
.transform((obj) => {
|
|
@@ -83,6 +87,7 @@ const SchemaOut$CreateRequest = z
|
|
|
83
87
|
maxFpsLimit: "max_fps_limit",
|
|
84
88
|
name: "name",
|
|
85
89
|
startSeconds: "start_seconds",
|
|
90
|
+
style: "style",
|
|
86
91
|
width: "width",
|
|
87
92
|
});
|
|
88
93
|
});
|
|
@@ -10,7 +10,9 @@ import { AiMemeGeneratorClient } from "../../resources/v1/ai-meme-generator";
|
|
|
10
10
|
import { AiPhotoEditorClient } from "../../resources/v1/ai-photo-editor";
|
|
11
11
|
import { AiQrCodeGeneratorClient } from "../../resources/v1/ai-qr-code-generator";
|
|
12
12
|
import { AiTalkingPhotoClient } from "../../resources/v1/ai-talking-photo";
|
|
13
|
+
import { AiVoiceGeneratorClient } from "../../resources/v1/ai-voice-generator";
|
|
13
14
|
import { AnimationClient } from "../../resources/v1/animation";
|
|
15
|
+
import { AudioProjectsClient } from "../../resources/v1/audio-projects";
|
|
14
16
|
import { AutoSubtitleGeneratorClient } from "../../resources/v1/auto-subtitle-generator";
|
|
15
17
|
import { FaceDetectionClient } from "../../resources/v1/face-detection";
|
|
16
18
|
import { FaceSwapClient } from "../../resources/v1/face-swap";
|
|
@@ -25,6 +27,8 @@ import { TextToVideoClient } from "../../resources/v1/text-to-video";
|
|
|
25
27
|
import { VideoProjectsClient } from "../../resources/v1/video-projects";
|
|
26
28
|
import { VideoToVideoClient } from "../../resources/v1/video-to-video";
|
|
27
29
|
export declare class V1Client extends CoreResourceClient {
|
|
30
|
+
private _audioProjectsLazy?;
|
|
31
|
+
private _aiVoiceGeneratorLazy?;
|
|
28
32
|
private _imageProjectsLazy?;
|
|
29
33
|
private _videoProjectsLazy?;
|
|
30
34
|
private _faceDetectionLazy?;
|
|
@@ -76,4 +80,6 @@ export declare class V1Client extends CoreResourceClient {
|
|
|
76
80
|
get photoColorizer(): PhotoColorizerClient;
|
|
77
81
|
get textToVideo(): TextToVideoClient;
|
|
78
82
|
get videoToVideo(): VideoToVideoClient;
|
|
83
|
+
get aiVoiceGenerator(): AiVoiceGeneratorClient;
|
|
84
|
+
get audioProjects(): AudioProjectsClient;
|
|
79
85
|
}
|