@magichourhq/ai-sdk-provider 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +88 -2
- package/dist/index.d.ts +18 -0
- package/dist/index.js +265 -0
- package/package.json +52 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Magic Hour AI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,89 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Magic Hour provider for the AI SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Generate images and videos with [Magic Hour](https://magichour.ai) from the [AI SDK](https://ai-sdk.dev).
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @magichourhq/ai-sdk-provider ai
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Requires AI SDK 7 and Node.js 22 or newer.
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
Set `MAGIC_HOUR_API_KEY`, then:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { experimental_generateVideo as generateVideo, generateImage } from "ai";
|
|
19
|
+
import { magichour } from "@magichourhq/ai-sdk-provider";
|
|
20
|
+
|
|
21
|
+
const { image } = await generateImage({
|
|
22
|
+
model: magichour.image("flux-2-klein"),
|
|
23
|
+
prompt: "A ceramic mug on a studio background",
|
|
24
|
+
aspectRatio: "1:1",
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const { video } = await generateVideo({
|
|
28
|
+
model: magichour.video("ltx-2.5"),
|
|
29
|
+
prompt: { image: image.uint8Array, text: "A slow camera push toward the mug" },
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
For text-to-video, pass a string prompt. An input image can be bytes, base64 or an HTTPS URL.
|
|
34
|
+
|
|
35
|
+
To configure the provider in code, use `createMagicHour`:
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { createMagicHour } from "@magichourhq/ai-sdk-provider";
|
|
39
|
+
|
|
40
|
+
const magichour = createMagicHour({ apiKey: process.env.MY_KEY, timeoutMs: 300_000 });
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
| Setting | Default |
|
|
44
|
+
| --- | --- |
|
|
45
|
+
| `apiKey` | `MAGIC_HOUR_API_KEY`, read when each call starts |
|
|
46
|
+
| `timeoutMs` | 10 minutes for the whole call: upload, generation and download |
|
|
47
|
+
| `pollIntervalMs` | 2 seconds |
|
|
48
|
+
| `onProjectCreated` | Called with `{ id, kind }` as soon as the job is accepted |
|
|
49
|
+
| `fetch` | The global `fetch` |
|
|
50
|
+
|
|
51
|
+
## Models and options
|
|
52
|
+
|
|
53
|
+
| | Image | Video |
|
|
54
|
+
| --- | --- | --- |
|
|
55
|
+
| Models | `default`, `flux-2-klein`, `z-image-turbo`, `qwen-image-2.1` | `default`, `ltx-2.5`, `minimax-h3`, `wan-2.2` |
|
|
56
|
+
| Resolution | `640px` (default), `1k`, `2k` | `360p`, `480p` (default), `720p`, `1080p`, `4k` |
|
|
57
|
+
| Aspect ratio | `1:1`, `16:9`, `9:16` | `1:1`, `16:9` (default), `9:16` |
|
|
58
|
+
|
|
59
|
+
- Set the resolution with `providerOptions: { magichour: { resolution } }`, or with the AI SDK's `size` for images (640, 1024 or 2048 on the longest edge) and `resolution` for videos (360, 480, 720, 1080 or 2160 on the shortest edge).
|
|
60
|
+
- Video `duration` is 1 to 60 seconds, 5 by default. `generateAudio` is passed through.
|
|
61
|
+
- Image-to-video keeps the input image's shape, so it takes no aspect ratio.
|
|
62
|
+
- Seeds, FPS, image editing and frame or reference inputs aren't supported. They throw before anything is sent.
|
|
63
|
+
- `default` follows Magic Hour's current recommendation, so its output and cost can change. Choose a model to keep them fixed. See [pricing](https://docs.magichour.ai/pricing).
|
|
64
|
+
|
|
65
|
+
## Credits and failures
|
|
66
|
+
|
|
67
|
+
Every generation is a paid job. The provider submits it once, waits for it to finish and downloads the result.
|
|
68
|
+
|
|
69
|
+
- **Paid requests are never retried**, by the provider or by the AI SDK. Don't wrap calls in your own retry.
|
|
70
|
+
- **Once a job is accepted, every error names it.** Errors are `MagicHourError` with a `projectId`. Fetch the result with `GET /v1/image-projects/{id}` or `GET /v1/video-projects/{id}` instead of generating again. To keep the ID even if the process dies, save it in `onProjectCreated`.
|
|
71
|
+
- **If a submission's outcome is unknown**, for example after a dropped connection, the error says so and has no `projectId`. Check your account history before submitting again.
|
|
72
|
+
- **Aborting stops waiting.** It doesn't cancel the job on Magic Hour.
|
|
73
|
+
|
|
74
|
+
The project ID and the credits charged are in `providerMetadata.magichour`.
|
|
75
|
+
|
|
76
|
+
## Development
|
|
77
|
+
|
|
78
|
+
```sh
|
|
79
|
+
yarn install
|
|
80
|
+
yarn check
|
|
81
|
+
yarn test
|
|
82
|
+
yarn build
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
`yarn example` generates a real image, and `yarn example --video` a video too. Both spend credits.
|
|
86
|
+
|
|
87
|
+
## License
|
|
88
|
+
|
|
89
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type ImageModelV4, type Experimental_VideoModelV4 as VideoModelV4, type ProviderV4 } from "@ai-sdk/provider";
|
|
2
|
+
import { type ClientSettings } from "@magichourhq/browser-client";
|
|
3
|
+
export { MagicHourError } from "@magichourhq/browser-client";
|
|
4
|
+
export type MagicHourSettings = Omit<ClientSettings, "apiKey"> & {
|
|
5
|
+
apiKey?: string;
|
|
6
|
+
};
|
|
7
|
+
declare const imageModels: readonly ["default", "flux-2-klein", "z-image-turbo", "qwen-image-2.1"];
|
|
8
|
+
declare const videoModels: readonly ["default", "ltx-2.5", "minimax-h3", "wan-2.2"];
|
|
9
|
+
export type MagicHourImageModelId = (typeof imageModels)[number];
|
|
10
|
+
export type MagicHourVideoModelId = (typeof videoModels)[number];
|
|
11
|
+
export interface MagicHourProvider extends Omit<ProviderV4, "imageModel"> {
|
|
12
|
+
image(modelId?: MagicHourImageModelId): ImageModelV4;
|
|
13
|
+
imageModel(modelId?: string): ImageModelV4;
|
|
14
|
+
video(modelId?: MagicHourVideoModelId): VideoModelV4;
|
|
15
|
+
videoModel(modelId?: MagicHourVideoModelId): VideoModelV4;
|
|
16
|
+
}
|
|
17
|
+
export declare function createMagicHour(settings?: MagicHourSettings): MagicHourProvider;
|
|
18
|
+
export declare const magichour: MagicHourProvider;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { NoSuchModelError, } from "@ai-sdk/provider";
|
|
2
|
+
import { MagicHourClient, MagicHourError, httpsURL, } from "@magichourhq/browser-client";
|
|
3
|
+
export { MagicHourError } from "@magichourhq/browser-client";
|
|
4
|
+
const imageModels = ["default", "flux-2-klein", "z-image-turbo", "qwen-image-2.1"];
|
|
5
|
+
const videoModels = ["default", "ltx-2.5", "minimax-h3", "wan-2.2"];
|
|
6
|
+
const aspectRatios = ["1:1", "16:9", "9:16"];
|
|
7
|
+
const imageResolutions = ["640px", "1k", "2k"];
|
|
8
|
+
const videoResolutions = ["360p", "480p", "720p", "1080p", "4k"];
|
|
9
|
+
function isOneOf(values, value) {
|
|
10
|
+
return values.includes(value);
|
|
11
|
+
}
|
|
12
|
+
function ratio(value) {
|
|
13
|
+
if (value === undefined)
|
|
14
|
+
return undefined;
|
|
15
|
+
if (!isOneOf(aspectRatios, value))
|
|
16
|
+
throw new Error("Supported aspect ratios: 1:1, 16:9, 9:16.");
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
function extra(options, allowed) {
|
|
20
|
+
const values = options.providerOptions?.magichour ?? {};
|
|
21
|
+
for (const key of Object.keys(values))
|
|
22
|
+
if (!allowed.includes(key))
|
|
23
|
+
throw new Error(`Unsupported Magic Hour option: ${key}.`);
|
|
24
|
+
return values;
|
|
25
|
+
}
|
|
26
|
+
function ascii(text) {
|
|
27
|
+
return [...text].map((c) => c.charCodeAt(0));
|
|
28
|
+
}
|
|
29
|
+
/** Checks the file signature, so mislabeled or non-image data never reaches a paid job. */
|
|
30
|
+
function hasSignature(bytes, extension) {
|
|
31
|
+
function startsWith(offset, signature) {
|
|
32
|
+
return signature.every((byte, i) => bytes[offset + i] === byte);
|
|
33
|
+
}
|
|
34
|
+
if (extension === "png")
|
|
35
|
+
return startsWith(0, [0x89, ...ascii("PNG\r\n"), 0x1a, 0x0a]);
|
|
36
|
+
if (extension === "jpg")
|
|
37
|
+
return startsWith(0, [0xff, 0xd8, 0xff]);
|
|
38
|
+
return startsWith(0, ascii("RIFF")) && startsWith(8, ascii("WEBP"));
|
|
39
|
+
}
|
|
40
|
+
/** Decodes strict base64, which `Buffer.from` would otherwise accept with characters dropped. */
|
|
41
|
+
function base64Bytes(value) {
|
|
42
|
+
if (!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value))
|
|
43
|
+
throw new Error("Image data must be base64.");
|
|
44
|
+
return new Uint8Array(Buffer.from(value, "base64"));
|
|
45
|
+
}
|
|
46
|
+
/** Parses "WIDTHxHEIGHT" with positive whole numbers. */
|
|
47
|
+
function dimensions(value) {
|
|
48
|
+
const match = /^([1-9]\d*)x([1-9]\d*)$/.exec(value);
|
|
49
|
+
if (!match)
|
|
50
|
+
throw new Error("Dimensions must look like 1024x1024.");
|
|
51
|
+
return [Number(match[1]), Number(match[2])];
|
|
52
|
+
}
|
|
53
|
+
function imageResolution(size, option) {
|
|
54
|
+
if (option !== undefined && !isOneOf(imageResolutions, option))
|
|
55
|
+
throw new Error("Image resolution must be 640px, 1k, or 2k.");
|
|
56
|
+
if (!size)
|
|
57
|
+
return option ?? "640px";
|
|
58
|
+
if (option !== undefined)
|
|
59
|
+
throw new Error("Use either size or providerOptions.magichour.resolution.");
|
|
60
|
+
// Magic Hour exposes longest-edge tiers, rather than arbitrary pixel sizes.
|
|
61
|
+
const edge = Math.max(...dimensions(size));
|
|
62
|
+
const tier = new Map([
|
|
63
|
+
[640, "640px"],
|
|
64
|
+
[1024, "1k"],
|
|
65
|
+
[2048, "2k"],
|
|
66
|
+
]).get(edge);
|
|
67
|
+
if (!tier)
|
|
68
|
+
throw new Error("Use a 640, 1024, or 2048 longest edge, or set providerOptions.magichour.resolution.");
|
|
69
|
+
return tier;
|
|
70
|
+
}
|
|
71
|
+
function ratioFromSize(size) {
|
|
72
|
+
if (!size)
|
|
73
|
+
return undefined;
|
|
74
|
+
const [w, h] = dimensions(size);
|
|
75
|
+
for (const r of aspectRatios) {
|
|
76
|
+
const [rw, rh] = r.split(":").map(Number);
|
|
77
|
+
if (Math.abs(w / h - rw / rh) < 0.002)
|
|
78
|
+
return r;
|
|
79
|
+
}
|
|
80
|
+
throw new Error("Dimensions must have a 1:1, 16:9, or 9:16 aspect ratio.");
|
|
81
|
+
}
|
|
82
|
+
export function createMagicHour(settings = {}) {
|
|
83
|
+
// Resolve credentials lazily so merely importing or registering the provider needs no key.
|
|
84
|
+
const client = () => new MagicHourClient({
|
|
85
|
+
...settings,
|
|
86
|
+
apiKey: settings.apiKey ?? process.env.MAGIC_HOUR_API_KEY ?? "",
|
|
87
|
+
});
|
|
88
|
+
function image(modelId = "default") {
|
|
89
|
+
if (!isOneOf(imageModels, modelId))
|
|
90
|
+
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
91
|
+
return {
|
|
92
|
+
specificationVersion: "v4",
|
|
93
|
+
provider: "magichour.image",
|
|
94
|
+
modelId,
|
|
95
|
+
maxImagesPerCall: 1,
|
|
96
|
+
supportsFileInputs: false,
|
|
97
|
+
supportsMaskInputs: false,
|
|
98
|
+
async doGenerate(options) {
|
|
99
|
+
if (!options.prompt?.trim())
|
|
100
|
+
throw new Error("An image prompt is required.");
|
|
101
|
+
if (options.n !== 1)
|
|
102
|
+
throw new Error("One image per request is supported.");
|
|
103
|
+
if (options.files?.length || options.mask)
|
|
104
|
+
throw new Error("This provider supports image generation, not image editing.");
|
|
105
|
+
if (options.seed !== undefined)
|
|
106
|
+
throw new Error("Magic Hour does not expose a seed parameter.");
|
|
107
|
+
const extras = extra(options, ["resolution"]);
|
|
108
|
+
const resolution = imageResolution(options.size, extras.resolution);
|
|
109
|
+
const sizeRatio = ratioFromSize(options.size);
|
|
110
|
+
if (sizeRatio && options.aspectRatio && sizeRatio !== options.aspectRatio)
|
|
111
|
+
throw new Error("size and aspectRatio disagree.");
|
|
112
|
+
const aspectRatio = ratio(options.aspectRatio ?? sizeRatio);
|
|
113
|
+
const transport = client();
|
|
114
|
+
const signal = transport.signal(options.abortSignal);
|
|
115
|
+
const timestamp = new Date();
|
|
116
|
+
const id = await transport.create("ai-image-generator", {
|
|
117
|
+
model: modelId,
|
|
118
|
+
image_count: 1,
|
|
119
|
+
resolution,
|
|
120
|
+
...(aspectRatio ? { aspect_ratio: aspectRatio } : {}),
|
|
121
|
+
style: { prompt: options.prompt },
|
|
122
|
+
}, signal, options.headers);
|
|
123
|
+
const project = await transport.wait(id, "image", signal, options.headers);
|
|
124
|
+
try {
|
|
125
|
+
const images = await Promise.all(project.downloads.slice(0, 1).map((d) => transport.download(d.url, signal)));
|
|
126
|
+
return {
|
|
127
|
+
images,
|
|
128
|
+
warnings: [],
|
|
129
|
+
isRetryable: false,
|
|
130
|
+
response: { timestamp, modelId, headers: undefined },
|
|
131
|
+
providerMetadata: {
|
|
132
|
+
magichour: {
|
|
133
|
+
projectId: id,
|
|
134
|
+
creditsCharged: project.credits_charged,
|
|
135
|
+
images: [{ projectId: id, creditsCharged: project.credits_charged }],
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
throw new MagicHourError("Could not download the generated image.", id);
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
function video(modelId = "default") {
|
|
147
|
+
if (!videoModels.includes(modelId))
|
|
148
|
+
throw new NoSuchModelError({ modelId, modelType: "videoModel" });
|
|
149
|
+
return {
|
|
150
|
+
specificationVersion: "v4",
|
|
151
|
+
provider: "magichour.video",
|
|
152
|
+
modelId,
|
|
153
|
+
maxVideosPerCall: 1,
|
|
154
|
+
async doGenerate(options) {
|
|
155
|
+
if (options.n !== 1)
|
|
156
|
+
throw new Error("One video per request is supported.");
|
|
157
|
+
if (!options.prompt?.trim() && !options.image)
|
|
158
|
+
throw new Error("A prompt or input image is required.");
|
|
159
|
+
if (options.seed !== undefined || options.fps !== undefined)
|
|
160
|
+
throw new Error("Magic Hour does not expose seed or FPS parameters.");
|
|
161
|
+
if (options.frameImages?.length || options.inputReferences?.length)
|
|
162
|
+
throw new Error("Frame and reference inputs are not supported by this adapter.");
|
|
163
|
+
const extras = extra(options, ["resolution"]);
|
|
164
|
+
if (extras.resolution !== undefined && !isOneOf(videoResolutions, extras.resolution))
|
|
165
|
+
throw new Error("Invalid Magic Hour video resolution.");
|
|
166
|
+
if (options.resolution && extras.resolution !== undefined)
|
|
167
|
+
throw new Error("Use either resolution or providerOptions.magichour.resolution.");
|
|
168
|
+
let resolution = extras.resolution ?? "480p";
|
|
169
|
+
const dimensionsRatio = ratioFromSize(options.resolution);
|
|
170
|
+
if (options.resolution) {
|
|
171
|
+
const shortEdge = Math.min(...dimensions(options.resolution));
|
|
172
|
+
const mapped = new Map([
|
|
173
|
+
[360, "360p"],
|
|
174
|
+
[480, "480p"],
|
|
175
|
+
[720, "720p"],
|
|
176
|
+
[1080, "1080p"],
|
|
177
|
+
[2160, "4k"],
|
|
178
|
+
]).get(shortEdge);
|
|
179
|
+
if (!mapped)
|
|
180
|
+
throw new Error("Unsupported video dimensions; use a resolution tier in providerOptions.magichour.");
|
|
181
|
+
resolution = mapped;
|
|
182
|
+
}
|
|
183
|
+
if (options.image && options.aspectRatio && options.aspectRatio !== "adaptive")
|
|
184
|
+
throw new Error("Image-to-video inherits the input image ratio; omit aspectRatio or use adaptive.");
|
|
185
|
+
if (!options.image && options.aspectRatio === "adaptive")
|
|
186
|
+
throw new Error("adaptive requires an input image.");
|
|
187
|
+
const aspectRatio = options.image
|
|
188
|
+
? undefined
|
|
189
|
+
: ratio(options.aspectRatio ?? dimensionsRatio);
|
|
190
|
+
if (!options.image &&
|
|
191
|
+
dimensionsRatio &&
|
|
192
|
+
options.aspectRatio &&
|
|
193
|
+
dimensionsRatio !== options.aspectRatio)
|
|
194
|
+
throw new Error("resolution and aspectRatio disagree.");
|
|
195
|
+
const duration = options.duration ?? 5;
|
|
196
|
+
if (!Number.isFinite(duration) || duration < 1 || duration > 60)
|
|
197
|
+
throw new Error("Duration must be between 1 and 60 seconds; model-specific limits also apply.");
|
|
198
|
+
// Validate all options before uploading input or submitting a paid generation.
|
|
199
|
+
const transport = client();
|
|
200
|
+
const signal = transport.signal(options.abortSignal);
|
|
201
|
+
let imagePath;
|
|
202
|
+
if (options.image?.type === "url")
|
|
203
|
+
imagePath = httpsURL(options.image.url);
|
|
204
|
+
else if (options.image?.type === "file") {
|
|
205
|
+
const extension = { "image/png": "png", "image/jpeg": "jpg", "image/webp": "webp" }[options.image.mediaType];
|
|
206
|
+
if (!extension)
|
|
207
|
+
throw new Error("Image-to-video accepts PNG, JPEG, or WebP.");
|
|
208
|
+
const bytes = typeof options.image.data === "string"
|
|
209
|
+
? base64Bytes(options.image.data)
|
|
210
|
+
: options.image.data;
|
|
211
|
+
if (!hasSignature(bytes, extension))
|
|
212
|
+
throw new Error(`The input image data isn't a ${extension.toUpperCase()} file.`);
|
|
213
|
+
imagePath = await transport.uploadImage(bytes, extension, signal);
|
|
214
|
+
}
|
|
215
|
+
const timestamp = new Date();
|
|
216
|
+
const shared = {
|
|
217
|
+
model: modelId,
|
|
218
|
+
end_seconds: duration,
|
|
219
|
+
resolution,
|
|
220
|
+
...(options.generateAudio !== undefined ? { audio: options.generateAudio } : {}),
|
|
221
|
+
};
|
|
222
|
+
const id = imagePath
|
|
223
|
+
? await transport.create("image-to-video", {
|
|
224
|
+
...shared,
|
|
225
|
+
...(options.prompt ? { style: { prompt: options.prompt } } : {}),
|
|
226
|
+
assets: { image_file_path: imagePath },
|
|
227
|
+
}, signal, options.headers)
|
|
228
|
+
: await transport.create("text-to-video", {
|
|
229
|
+
...shared,
|
|
230
|
+
style: { prompt: options.prompt ?? "" },
|
|
231
|
+
aspect_ratio: aspectRatio ?? "16:9",
|
|
232
|
+
}, signal, options.headers);
|
|
233
|
+
const project = await transport.wait(id, "video", signal, options.headers);
|
|
234
|
+
try {
|
|
235
|
+
const data = await transport.download(project.downloads[0].url, signal);
|
|
236
|
+
return {
|
|
237
|
+
videos: [{ type: "binary", data, mediaType: "video/mp4" }],
|
|
238
|
+
warnings: [],
|
|
239
|
+
response: { timestamp, modelId, headers: undefined },
|
|
240
|
+
providerMetadata: {
|
|
241
|
+
magichour: { projectId: id, creditsCharged: project.credits_charged },
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
catch {
|
|
246
|
+
throw new MagicHourError("Could not download the generated video.", id);
|
|
247
|
+
}
|
|
248
|
+
},
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
return {
|
|
252
|
+
specificationVersion: "v4",
|
|
253
|
+
image,
|
|
254
|
+
imageModel: image,
|
|
255
|
+
video,
|
|
256
|
+
videoModel: video,
|
|
257
|
+
languageModel(modelId) {
|
|
258
|
+
throw new NoSuchModelError({ modelId, modelType: "languageModel" });
|
|
259
|
+
},
|
|
260
|
+
embeddingModel(modelId) {
|
|
261
|
+
throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
|
|
262
|
+
},
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
export const magichour = createMagicHour();
|
package/package.json
CHANGED
|
@@ -1,6 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@magichourhq/ai-sdk-provider",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"packageManager": "yarn@4.18.0",
|
|
5
|
+
"description": "Magic Hour image and video provider for the AI SDK",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">=22"
|
|
10
|
+
},
|
|
11
|
+
"main": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/magichourhq/ai-sdk-provider.git"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsc -p tsconfig.json",
|
|
29
|
+
"test": "vitest run",
|
|
30
|
+
"check": "tsc --noEmit -p tsconfig.test.json",
|
|
31
|
+
"example": "tsx example.ts",
|
|
32
|
+
"prepack": "yarn build"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@ai-sdk/provider": "^4.0.31",
|
|
36
|
+
"@magichourhq/browser-client": "^0.3.2"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/node": "^24.0.0",
|
|
40
|
+
"@vitest/coverage-v8": "^5.1.0",
|
|
41
|
+
"ai": "^7.0.148",
|
|
42
|
+
"tsx": "^4.20.0",
|
|
43
|
+
"typescript": "^7.0.2",
|
|
44
|
+
"vite": "^8.3.8",
|
|
45
|
+
"vitest": "^5.1.0",
|
|
46
|
+
"zod": "^4.6.7"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"ai": "^7.0.0"
|
|
50
|
+
},
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"access": "public",
|
|
53
|
+
"registry": "https://registry.npmjs.org/"
|
|
54
|
+
}
|
|
6
55
|
}
|