@ai-sdk/luma 2.0.0-beta.53 → 2.0.0-beta.55
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/CHANGELOG.md +16 -0
- package/README.md +1 -1
- package/dist/index.d.mts +19 -2
- package/dist/index.d.ts +19 -2
- package/dist/index.js +178 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +182 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @ai-sdk/luma
|
|
2
2
|
|
|
3
|
+
## 2.0.0-beta.55
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [50b70d6]
|
|
8
|
+
- @ai-sdk/provider-utils@4.0.0-beta.55
|
|
9
|
+
|
|
10
|
+
## 2.0.0-beta.54
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 9061dc0: feat: image editing
|
|
15
|
+
- Updated dependencies [9061dc0]
|
|
16
|
+
- @ai-sdk/provider-utils@4.0.0-beta.54
|
|
17
|
+
- @ai-sdk/provider@3.0.0-beta.28
|
|
18
|
+
|
|
3
19
|
## 2.0.0-beta.53
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ import { luma } from '@ai-sdk/luma';
|
|
|
34
34
|
|
|
35
35
|
```ts
|
|
36
36
|
import { luma } from '@ai-sdk/luma';
|
|
37
|
-
import {
|
|
37
|
+
import { generateImage } from 'ai';
|
|
38
38
|
import fs from 'fs';
|
|
39
39
|
|
|
40
40
|
const { image } = await generateImage({
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ProviderV3, ImageModelV3 } from '@ai-sdk/provider';
|
|
2
|
-
import
|
|
2
|
+
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
3
|
+
import { FetchFunction, InferSchema } from '@ai-sdk/provider-utils';
|
|
3
4
|
import { z } from 'zod/v4';
|
|
4
5
|
|
|
5
6
|
type LumaImageModelId = 'photon-1' | 'photon-flash-1' | (string & {});
|
|
@@ -53,7 +54,23 @@ declare const lumaErrorSchema: z.ZodObject<{
|
|
|
53
54
|
}, z.core.$strip>>;
|
|
54
55
|
}, z.core.$strip>;
|
|
55
56
|
type LumaErrorData = z.infer<typeof lumaErrorSchema>;
|
|
57
|
+
/**
|
|
58
|
+
* Provider options schema for Luma image generation.
|
|
59
|
+
*
|
|
60
|
+
* @see https://docs.lumalabs.ai/docs/image-generation
|
|
61
|
+
*/
|
|
62
|
+
declare const lumaImageProviderOptionsSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
63
|
+
[x: string]: unknown;
|
|
64
|
+
referenceType?: "image" | "style" | "character" | "modify_image" | null | undefined;
|
|
65
|
+
images?: {
|
|
66
|
+
weight?: number | null | undefined;
|
|
67
|
+
id?: string | null | undefined;
|
|
68
|
+
}[] | null | undefined;
|
|
69
|
+
pollIntervalMillis?: number | null | undefined;
|
|
70
|
+
maxPollAttempts?: number | null | undefined;
|
|
71
|
+
}>;
|
|
72
|
+
type LumaImageProviderOptions = InferSchema<typeof lumaImageProviderOptionsSchema>;
|
|
56
73
|
|
|
57
74
|
declare const VERSION: string;
|
|
58
75
|
|
|
59
|
-
export { type LumaErrorData, type LumaProvider, type LumaProviderSettings, VERSION, createLuma, luma };
|
|
76
|
+
export { type LumaErrorData, type LumaImageProviderOptions, type LumaProvider, type LumaProviderSettings, VERSION, createLuma, luma };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ProviderV3, ImageModelV3 } from '@ai-sdk/provider';
|
|
2
|
-
import
|
|
2
|
+
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
3
|
+
import { FetchFunction, InferSchema } from '@ai-sdk/provider-utils';
|
|
3
4
|
import { z } from 'zod/v4';
|
|
4
5
|
|
|
5
6
|
type LumaImageModelId = 'photon-1' | 'photon-flash-1' | (string & {});
|
|
@@ -53,7 +54,23 @@ declare const lumaErrorSchema: z.ZodObject<{
|
|
|
53
54
|
}, z.core.$strip>>;
|
|
54
55
|
}, z.core.$strip>;
|
|
55
56
|
type LumaErrorData = z.infer<typeof lumaErrorSchema>;
|
|
57
|
+
/**
|
|
58
|
+
* Provider options schema for Luma image generation.
|
|
59
|
+
*
|
|
60
|
+
* @see https://docs.lumalabs.ai/docs/image-generation
|
|
61
|
+
*/
|
|
62
|
+
declare const lumaImageProviderOptionsSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
63
|
+
[x: string]: unknown;
|
|
64
|
+
referenceType?: "image" | "style" | "character" | "modify_image" | null | undefined;
|
|
65
|
+
images?: {
|
|
66
|
+
weight?: number | null | undefined;
|
|
67
|
+
id?: string | null | undefined;
|
|
68
|
+
}[] | null | undefined;
|
|
69
|
+
pollIntervalMillis?: number | null | undefined;
|
|
70
|
+
maxPollAttempts?: number | null | undefined;
|
|
71
|
+
}>;
|
|
72
|
+
type LumaImageProviderOptions = InferSchema<typeof lumaImageProviderOptionsSchema>;
|
|
56
73
|
|
|
57
74
|
declare const VERSION: string;
|
|
58
75
|
|
|
59
|
-
export { type LumaErrorData, type LumaProvider, type LumaProviderSettings, VERSION, createLuma, luma };
|
|
76
|
+
export { type LumaErrorData, type LumaImageProviderOptions, type LumaProvider, type LumaProviderSettings, VERSION, createLuma, luma };
|
package/dist/index.js
CHANGED
|
@@ -56,9 +56,11 @@ var LumaImageModel = class {
|
|
|
56
56
|
seed,
|
|
57
57
|
providerOptions,
|
|
58
58
|
headers,
|
|
59
|
-
abortSignal
|
|
59
|
+
abortSignal,
|
|
60
|
+
files,
|
|
61
|
+
mask
|
|
60
62
|
}) {
|
|
61
|
-
var _a, _b, _c
|
|
63
|
+
var _a, _b, _c;
|
|
62
64
|
const warnings = [];
|
|
63
65
|
if (seed != null) {
|
|
64
66
|
warnings.push({
|
|
@@ -74,8 +76,25 @@ var LumaImageModel = class {
|
|
|
74
76
|
details: "This model does not support the `size` option. Use `aspectRatio` instead."
|
|
75
77
|
});
|
|
76
78
|
}
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
+
const lumaOptions = await (0, import_provider_utils.parseProviderOptions)({
|
|
80
|
+
provider: "luma",
|
|
81
|
+
providerOptions,
|
|
82
|
+
schema: lumaImageProviderOptionsSchema
|
|
83
|
+
});
|
|
84
|
+
const {
|
|
85
|
+
pollIntervalMillis,
|
|
86
|
+
maxPollAttempts,
|
|
87
|
+
referenceType,
|
|
88
|
+
images: imageConfigs,
|
|
89
|
+
...providerRequestOptions
|
|
90
|
+
} = lumaOptions != null ? lumaOptions : {};
|
|
91
|
+
const editingOptions = this.getEditingOptions(
|
|
92
|
+
files,
|
|
93
|
+
mask,
|
|
94
|
+
referenceType != null ? referenceType : void 0,
|
|
95
|
+
imageConfigs != null ? imageConfigs : []
|
|
96
|
+
);
|
|
97
|
+
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
79
98
|
const fullHeaders = (0, import_provider_utils.combineHeaders)(this.config.headers(), headers);
|
|
80
99
|
const { value: generationResponse, responseHeaders } = await (0, import_provider_utils.postJsonToApi)({
|
|
81
100
|
url: this.getLumaGenerationsUrl(),
|
|
@@ -84,6 +103,7 @@ var LumaImageModel = class {
|
|
|
84
103
|
prompt,
|
|
85
104
|
...aspectRatio ? { aspect_ratio: aspectRatio } : {},
|
|
86
105
|
model: this.modelId,
|
|
106
|
+
...editingOptions,
|
|
87
107
|
...providerRequestOptions
|
|
88
108
|
},
|
|
89
109
|
abortSignal,
|
|
@@ -97,7 +117,10 @@ var LumaImageModel = class {
|
|
|
97
117
|
generationResponse.id,
|
|
98
118
|
fullHeaders,
|
|
99
119
|
abortSignal,
|
|
100
|
-
|
|
120
|
+
{
|
|
121
|
+
pollIntervalMillis: pollIntervalMillis != null ? pollIntervalMillis : void 0,
|
|
122
|
+
maxPollAttempts: maxPollAttempts != null ? maxPollAttempts : void 0
|
|
123
|
+
}
|
|
101
124
|
);
|
|
102
125
|
const downloadedImage = await this.downloadImage(imageUrl, abortSignal);
|
|
103
126
|
return {
|
|
@@ -110,11 +133,11 @@ var LumaImageModel = class {
|
|
|
110
133
|
}
|
|
111
134
|
};
|
|
112
135
|
}
|
|
113
|
-
async pollForImageUrl(generationId, headers, abortSignal,
|
|
136
|
+
async pollForImageUrl(generationId, headers, abortSignal, pollSettings) {
|
|
114
137
|
var _a, _b, _c;
|
|
115
138
|
const url = this.getLumaGenerationsUrl(generationId);
|
|
116
|
-
const maxPollAttempts = (_a =
|
|
117
|
-
const pollIntervalMillis = (_b =
|
|
139
|
+
const maxPollAttempts = (_a = pollSettings == null ? void 0 : pollSettings.maxPollAttempts) != null ? _a : this.maxPollAttempts;
|
|
140
|
+
const pollIntervalMillis = (_b = pollSettings == null ? void 0 : pollSettings.pollIntervalMillis) != null ? _b : this.pollIntervalMillis;
|
|
118
141
|
for (let i = 0; i < maxPollAttempts; i++) {
|
|
119
142
|
const { value: statusResponse } = await (0, import_provider_utils.getFromApi)({
|
|
120
143
|
url,
|
|
@@ -156,6 +179,94 @@ var LumaImageModel = class {
|
|
|
156
179
|
}
|
|
157
180
|
});
|
|
158
181
|
}
|
|
182
|
+
getEditingOptions(files, mask, referenceType = "image", imageConfigs = []) {
|
|
183
|
+
var _a, _b, _c, _d;
|
|
184
|
+
const options = {};
|
|
185
|
+
if (mask != null) {
|
|
186
|
+
throw new Error(
|
|
187
|
+
"Luma AI does not support mask-based image editing. Use the prompt to describe the changes you want to make, along with `prompt.images` containing the source image URL."
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
if (files == null || files.length === 0) {
|
|
191
|
+
return options;
|
|
192
|
+
}
|
|
193
|
+
for (const file of files) {
|
|
194
|
+
if (file.type !== "url") {
|
|
195
|
+
throw new Error(
|
|
196
|
+
"Luma AI only supports URL-based images. Please provide image URLs using `prompt.images` with publicly accessible URLs. Base64 and Uint8Array data are not supported."
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
const defaultWeights = {
|
|
201
|
+
image: 0.85,
|
|
202
|
+
style: 0.8,
|
|
203
|
+
character: 1,
|
|
204
|
+
// Not used, but defined for completeness
|
|
205
|
+
modify_image: 1
|
|
206
|
+
};
|
|
207
|
+
switch (referenceType) {
|
|
208
|
+
case "image": {
|
|
209
|
+
if (files.length > 4) {
|
|
210
|
+
throw new Error(
|
|
211
|
+
`Luma AI image supports up to 4 reference images. You provided ${files.length} images.`
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
options.image = files.map((file, index) => {
|
|
215
|
+
var _a2, _b2;
|
|
216
|
+
return {
|
|
217
|
+
url: file.url,
|
|
218
|
+
weight: (_b2 = (_a2 = imageConfigs[index]) == null ? void 0 : _a2.weight) != null ? _b2 : defaultWeights.image
|
|
219
|
+
};
|
|
220
|
+
});
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
case "style": {
|
|
224
|
+
options.style = files.map((file, index) => {
|
|
225
|
+
var _a2, _b2;
|
|
226
|
+
return {
|
|
227
|
+
url: file.url,
|
|
228
|
+
weight: (_b2 = (_a2 = imageConfigs[index]) == null ? void 0 : _a2.weight) != null ? _b2 : defaultWeights.style
|
|
229
|
+
};
|
|
230
|
+
});
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
case "character": {
|
|
234
|
+
const identities = {};
|
|
235
|
+
for (let i = 0; i < files.length; i++) {
|
|
236
|
+
const file = files[i];
|
|
237
|
+
const identityId = (_b = (_a = imageConfigs[i]) == null ? void 0 : _a.id) != null ? _b : "identity0";
|
|
238
|
+
if (!identities[identityId]) {
|
|
239
|
+
identities[identityId] = [];
|
|
240
|
+
}
|
|
241
|
+
identities[identityId].push(file.url);
|
|
242
|
+
}
|
|
243
|
+
for (const [identityId, images] of Object.entries(identities)) {
|
|
244
|
+
if (images.length > 4) {
|
|
245
|
+
throw new Error(
|
|
246
|
+
`Luma AI character supports up to 4 images per identity. Identity '${identityId}' has ${images.length} images.`
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
options.character = Object.fromEntries(
|
|
251
|
+
Object.entries(identities).map(([id, images]) => [id, { images }])
|
|
252
|
+
);
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
case "modify_image": {
|
|
256
|
+
if (files.length > 1) {
|
|
257
|
+
throw new Error(
|
|
258
|
+
`Luma AI modify_image only supports a single input image. You provided ${files.length} images.`
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
options.modify_image = {
|
|
262
|
+
url: files[0].url,
|
|
263
|
+
weight: (_d = (_c = imageConfigs[0]) == null ? void 0 : _c.weight) != null ? _d : defaultWeights.modify_image
|
|
264
|
+
};
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return options;
|
|
269
|
+
}
|
|
159
270
|
getLumaGenerationsUrl(generationId) {
|
|
160
271
|
return `${this.config.baseURL}/dream-machine/v1/generations/${generationId != null ? generationId : "image"}`;
|
|
161
272
|
}
|
|
@@ -172,15 +283,19 @@ var LumaImageModel = class {
|
|
|
172
283
|
return response;
|
|
173
284
|
}
|
|
174
285
|
};
|
|
175
|
-
var lumaGenerationResponseSchema =
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
286
|
+
var lumaGenerationResponseSchema = (0, import_provider_utils.lazySchema)(
|
|
287
|
+
() => (0, import_provider_utils.zodSchema)(
|
|
288
|
+
import_v4.z.object({
|
|
289
|
+
id: import_v4.z.string(),
|
|
290
|
+
state: import_v4.z.enum(["queued", "dreaming", "completed", "failed"]),
|
|
291
|
+
failure_reason: import_v4.z.string().nullish(),
|
|
292
|
+
assets: import_v4.z.object({
|
|
293
|
+
image: import_v4.z.string()
|
|
294
|
+
// URL of the generated image
|
|
295
|
+
}).nullish()
|
|
296
|
+
})
|
|
297
|
+
)
|
|
298
|
+
);
|
|
184
299
|
var lumaErrorSchema = import_v4.z.object({
|
|
185
300
|
detail: import_v4.z.array(
|
|
186
301
|
import_v4.z.object({
|
|
@@ -194,9 +309,54 @@ var lumaErrorSchema = import_v4.z.object({
|
|
|
194
309
|
})
|
|
195
310
|
)
|
|
196
311
|
});
|
|
312
|
+
var lumaImageProviderOptionsSchema = (0, import_provider_utils.lazySchema)(
|
|
313
|
+
() => (0, import_provider_utils.zodSchema)(
|
|
314
|
+
import_v4.z.object({
|
|
315
|
+
/**
|
|
316
|
+
* The type of image reference to use when providing input images.
|
|
317
|
+
* - `image`: Guide generation using reference images (up to 4). Default.
|
|
318
|
+
* - `style`: Apply a specific style from reference image(s).
|
|
319
|
+
* - `character`: Create consistent characters from reference images (up to 4).
|
|
320
|
+
* - `modify_image`: Transform a single input image with prompt guidance.
|
|
321
|
+
*/
|
|
322
|
+
referenceType: import_v4.z.enum(["image", "style", "character", "modify_image"]).nullish(),
|
|
323
|
+
/**
|
|
324
|
+
* Per-image configuration array. Each entry corresponds to an image in `prompt.images`.
|
|
325
|
+
* Allows setting individual weights for each reference image.
|
|
326
|
+
*/
|
|
327
|
+
images: import_v4.z.array(
|
|
328
|
+
import_v4.z.object({
|
|
329
|
+
/**
|
|
330
|
+
* The weight of this image's influence on the generation.
|
|
331
|
+
* - For `image`: Higher weight = closer to reference (default: 0.85)
|
|
332
|
+
* - For `style`: Higher weight = stronger style influence (default: 0.8)
|
|
333
|
+
* - For `modify_image`: Higher weight = closer to input, lower = more creative (default: 1.0)
|
|
334
|
+
*/
|
|
335
|
+
weight: import_v4.z.number().min(0).max(1).nullish(),
|
|
336
|
+
/**
|
|
337
|
+
* The identity name for character references.
|
|
338
|
+
* Used with `character` to specify which identity group the image belongs to.
|
|
339
|
+
* Luma supports multiple identities (e.g., 'identity0', 'identity1') for generating
|
|
340
|
+
* images with multiple consistent characters.
|
|
341
|
+
* Default: 'identity0'
|
|
342
|
+
*/
|
|
343
|
+
id: import_v4.z.string().nullish()
|
|
344
|
+
})
|
|
345
|
+
).nullish(),
|
|
346
|
+
/**
|
|
347
|
+
* Override the polling interval in milliseconds (default 500).
|
|
348
|
+
*/
|
|
349
|
+
pollIntervalMillis: import_v4.z.number().nullish(),
|
|
350
|
+
/**
|
|
351
|
+
* Override the maximum number of polling attempts (default 120).
|
|
352
|
+
*/
|
|
353
|
+
maxPollAttempts: import_v4.z.number().nullish()
|
|
354
|
+
}).passthrough()
|
|
355
|
+
)
|
|
356
|
+
);
|
|
197
357
|
|
|
198
358
|
// src/version.ts
|
|
199
|
-
var VERSION = true ? "2.0.0-beta.
|
|
359
|
+
var VERSION = true ? "2.0.0-beta.55" : "0.0.0-test";
|
|
200
360
|
|
|
201
361
|
// src/luma-provider.ts
|
|
202
362
|
var defaultBaseURL = "https://api.lumalabs.ai";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/luma-provider.ts","../src/luma-image-model.ts","../src/version.ts"],"sourcesContent":["export { createLuma, luma } from './luma-provider';\nexport type { LumaProvider, LumaProviderSettings } from './luma-provider';\nexport type { LumaErrorData } from './luma-image-model';\nexport { VERSION } from './version';\n","import { ImageModelV3, NoSuchModelError, ProviderV3 } from '@ai-sdk/provider';\nimport {\n FetchFunction,\n loadApiKey,\n withoutTrailingSlash,\n withUserAgentSuffix,\n} from '@ai-sdk/provider-utils';\nimport { LumaImageModel } from './luma-image-model';\nimport { LumaImageModelId } from './luma-image-settings';\nimport { VERSION } from './version';\n\nexport interface LumaProviderSettings {\n /**\nLuma API key. Default value is taken from the `LUMA_API_KEY` environment\nvariable.\n */\n apiKey?: string;\n /**\nBase URL for the API calls.\n */\n baseURL?: string;\n /**\nCustom headers to include in the requests.\n */\n headers?: Record<string, string>;\n /**\nCustom fetch implementation. You can use it as a middleware to intercept requests,\nor to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\nexport interface LumaProvider extends ProviderV3 {\n /**\nCreates a model for image generation.\n */\n image(modelId: LumaImageModelId): ImageModelV3;\n\n /**\nCreates a model for image generation.\n */\n imageModel(modelId: LumaImageModelId): ImageModelV3;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(modelId: string): never;\n}\n\nconst defaultBaseURL = 'https://api.lumalabs.ai';\n\nexport function createLuma(options: LumaProviderSettings = {}): LumaProvider {\n const baseURL = withoutTrailingSlash(options.baseURL ?? defaultBaseURL);\n const getHeaders = () =>\n withUserAgentSuffix(\n {\n Authorization: `Bearer ${loadApiKey({\n apiKey: options.apiKey,\n environmentVariableName: 'LUMA_API_KEY',\n description: 'Luma',\n })}`,\n ...options.headers,\n },\n `ai-sdk/luma/${VERSION}`,\n );\n\n const createImageModel = (modelId: LumaImageModelId) =>\n new LumaImageModel(modelId, {\n provider: 'luma.image',\n baseURL: baseURL ?? defaultBaseURL,\n headers: getHeaders,\n fetch: options.fetch,\n });\n\n const embeddingModel = (modelId: string) => {\n throw new NoSuchModelError({\n modelId,\n modelType: 'embeddingModel',\n });\n };\n\n return {\n specificationVersion: 'v3' as const,\n image: createImageModel,\n imageModel: createImageModel,\n languageModel: (modelId: string) => {\n throw new NoSuchModelError({\n modelId,\n modelType: 'languageModel',\n });\n },\n embeddingModel,\n textEmbeddingModel: embeddingModel,\n };\n}\n\nexport const luma = createLuma();\n","import {\n ImageModelV3,\n SharedV3Warning,\n InvalidResponseDataError,\n} from '@ai-sdk/provider';\nimport {\n FetchFunction,\n combineHeaders,\n createBinaryResponseHandler,\n createJsonResponseHandler,\n createJsonErrorResponseHandler,\n createStatusCodeErrorResponseHandler,\n delay,\n getFromApi,\n postJsonToApi,\n} from '@ai-sdk/provider-utils';\nimport { LumaImageSettings } from './luma-image-settings';\nimport { z } from 'zod/v4';\n\nconst DEFAULT_POLL_INTERVAL_MILLIS = 500;\nconst DEFAULT_MAX_POLL_ATTEMPTS = 60000 / DEFAULT_POLL_INTERVAL_MILLIS;\n\ninterface LumaImageModelConfig {\n provider: string;\n baseURL: string;\n headers: () => Record<string, string>;\n fetch?: FetchFunction;\n _internal?: {\n currentDate?: () => Date;\n };\n}\n\nexport class LumaImageModel implements ImageModelV3 {\n readonly specificationVersion = 'v3';\n readonly maxImagesPerCall = 1;\n readonly pollIntervalMillis = DEFAULT_POLL_INTERVAL_MILLIS;\n readonly maxPollAttempts = DEFAULT_MAX_POLL_ATTEMPTS;\n\n get provider(): string {\n return this.config.provider;\n }\n\n constructor(\n readonly modelId: string,\n private readonly config: LumaImageModelConfig,\n ) {}\n\n async doGenerate({\n prompt,\n n,\n size,\n aspectRatio,\n seed,\n providerOptions,\n headers,\n abortSignal,\n }: Parameters<ImageModelV3['doGenerate']>[0]): Promise<\n Awaited<ReturnType<ImageModelV3['doGenerate']>>\n > {\n const warnings: Array<SharedV3Warning> = [];\n\n if (seed != null) {\n warnings.push({\n type: 'unsupported',\n feature: 'seed',\n details: 'This model does not support the `seed` option.',\n });\n }\n\n if (size != null) {\n warnings.push({\n type: 'unsupported',\n feature: 'size',\n details:\n 'This model does not support the `size` option. Use `aspectRatio` instead.',\n });\n }\n\n // remove non-request options from providerOptions\n const { pollIntervalMillis, maxPollAttempts, ...providerRequestOptions } =\n providerOptions.luma ?? {};\n\n const currentDate = this.config._internal?.currentDate?.() ?? new Date();\n const fullHeaders = combineHeaders(this.config.headers(), headers);\n const { value: generationResponse, responseHeaders } = await postJsonToApi({\n url: this.getLumaGenerationsUrl(),\n headers: fullHeaders,\n body: {\n prompt,\n ...(aspectRatio ? { aspect_ratio: aspectRatio } : {}),\n model: this.modelId,\n ...providerRequestOptions,\n },\n abortSignal,\n fetch: this.config.fetch,\n failedResponseHandler: this.createLumaErrorHandler(),\n successfulResponseHandler: createJsonResponseHandler(\n lumaGenerationResponseSchema,\n ),\n });\n\n const imageUrl = await this.pollForImageUrl(\n generationResponse.id,\n fullHeaders,\n abortSignal,\n providerOptions.luma,\n );\n\n const downloadedImage = await this.downloadImage(imageUrl, abortSignal);\n\n return {\n images: [downloadedImage],\n warnings,\n response: {\n modelId: this.modelId,\n timestamp: currentDate,\n headers: responseHeaders,\n },\n };\n }\n\n private async pollForImageUrl(\n generationId: string,\n headers: Record<string, string | undefined>,\n abortSignal: AbortSignal | undefined,\n imageSettings?: LumaImageSettings,\n ): Promise<string> {\n const url = this.getLumaGenerationsUrl(generationId);\n const maxPollAttempts =\n imageSettings?.maxPollAttempts ?? this.maxPollAttempts;\n const pollIntervalMillis =\n imageSettings?.pollIntervalMillis ?? this.pollIntervalMillis;\n\n for (let i = 0; i < maxPollAttempts; i++) {\n const { value: statusResponse } = await getFromApi({\n url,\n headers,\n abortSignal,\n fetch: this.config.fetch,\n failedResponseHandler: this.createLumaErrorHandler(),\n successfulResponseHandler: createJsonResponseHandler(\n lumaGenerationResponseSchema,\n ),\n });\n\n switch (statusResponse.state) {\n case 'completed':\n if (!statusResponse.assets?.image) {\n throw new InvalidResponseDataError({\n data: statusResponse,\n message: `Image generation completed but no image was found.`,\n });\n }\n return statusResponse.assets.image;\n case 'failed':\n throw new InvalidResponseDataError({\n data: statusResponse,\n message: `Image generation failed.`,\n });\n }\n await delay(pollIntervalMillis);\n }\n\n throw new Error(\n `Image generation timed out after ${this.maxPollAttempts} attempts.`,\n );\n }\n\n private createLumaErrorHandler() {\n return createJsonErrorResponseHandler({\n errorSchema: lumaErrorSchema,\n errorToMessage: (error: LumaErrorData) =>\n error.detail[0].msg ?? 'Unknown error',\n });\n }\n\n private getLumaGenerationsUrl(generationId?: string) {\n return `${this.config.baseURL}/dream-machine/v1/generations/${\n generationId ?? 'image'\n }`;\n }\n\n private async downloadImage(\n url: string,\n abortSignal: AbortSignal | undefined,\n ): Promise<Uint8Array> {\n const { value: response } = await getFromApi({\n url,\n // No specific headers should be needed for this request as it's a\n // generated image provided by Luma.\n abortSignal,\n failedResponseHandler: createStatusCodeErrorResponseHandler(),\n successfulResponseHandler: createBinaryResponseHandler(),\n fetch: this.config.fetch,\n });\n return response;\n }\n}\n\n// limited version of the schema, focussed on what is needed for the implementation\n// this approach limits breakages when the API changes and increases efficiency\nconst lumaGenerationResponseSchema = z.object({\n id: z.string(),\n state: z.enum(['queued', 'dreaming', 'completed', 'failed']),\n failure_reason: z.string().nullish(),\n assets: z\n .object({\n image: z.string(), // URL of the generated image\n })\n .nullish(),\n});\n\nconst lumaErrorSchema = z.object({\n detail: z.array(\n z.object({\n type: z.string(),\n loc: z.array(z.string()),\n msg: z.string(),\n input: z.string(),\n ctx: z\n .object({\n expected: z.string(),\n })\n .nullish(),\n }),\n ),\n});\n\nexport type LumaErrorData = z.infer<typeof lumaErrorSchema>;\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,mBAA2D;AAC3D,IAAAC,yBAKO;;;ACNP,sBAIO;AACP,4BAUO;AAEP,gBAAkB;AAElB,IAAM,+BAA+B;AACrC,IAAM,4BAA4B,MAAQ;AAYnC,IAAM,iBAAN,MAA6C;AAAA,EAUlD,YACW,SACQ,QACjB;AAFS;AACQ;AAXnB,SAAS,uBAAuB;AAChC,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB;AAAA,EASxB;AAAA,EAPH,IAAI,WAAmB;AACrB,WAAO,KAAK,OAAO;AAAA,EACrB;AAAA,EAOA,MAAM,WAAW;AAAA,IACf;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAEE;AA1DJ;AA2DI,UAAM,WAAmC,CAAC;AAE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AAQ;AAAA,EACjB,CAAC;AAEH,QAAM,iBAAiB,CAAC,YAAoB;AAC1C,UAAM,IAAI,kCAAiB;AAAA,MACzB;AAAA,MACA,WAAW;AAAA,IACb,CAAC;AAAA,EACH;AAEA,SAAO;AAAA,IACL,sBAAsB;AAAA,IACtB,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,eAAe,CAAC,YAAoB;AAClC,YAAM,IAAI,kCAAiB;AAAA,QACzB;AAAA,QACA,WAAW;AAAA,MACb,CAAC;AAAA,IACH;AAAA,IACA;AAAA,IACA,oBAAoB;AAAA,EACtB;AACF;AAEO,IAAM,OAAO,WAAW;","names":["import_provider","import_provider_utils"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/luma-provider.ts","../src/luma-image-model.ts","../src/version.ts"],"sourcesContent":["export { createLuma, luma } from './luma-provider';\nexport type { LumaProvider, LumaProviderSettings } from './luma-provider';\nexport type {\n LumaErrorData,\n LumaImageProviderOptions,\n} from './luma-image-model';\nexport { VERSION } from './version';\n","import { ImageModelV3, NoSuchModelError, ProviderV3 } from '@ai-sdk/provider';\nimport {\n FetchFunction,\n loadApiKey,\n withoutTrailingSlash,\n withUserAgentSuffix,\n} from '@ai-sdk/provider-utils';\nimport { LumaImageModel } from './luma-image-model';\nimport { LumaImageModelId } from './luma-image-settings';\nimport { VERSION } from './version';\n\nexport interface LumaProviderSettings {\n /**\nLuma API key. Default value is taken from the `LUMA_API_KEY` environment\nvariable.\n */\n apiKey?: string;\n /**\nBase URL for the API calls.\n */\n baseURL?: string;\n /**\nCustom headers to include in the requests.\n */\n headers?: Record<string, string>;\n /**\nCustom fetch implementation. You can use it as a middleware to intercept requests,\nor to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\nexport interface LumaProvider extends ProviderV3 {\n /**\nCreates a model for image generation.\n */\n image(modelId: LumaImageModelId): ImageModelV3;\n\n /**\nCreates a model for image generation.\n */\n imageModel(modelId: LumaImageModelId): ImageModelV3;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(modelId: string): never;\n}\n\nconst defaultBaseURL = 'https://api.lumalabs.ai';\n\nexport function createLuma(options: LumaProviderSettings = {}): LumaProvider {\n const baseURL = withoutTrailingSlash(options.baseURL ?? defaultBaseURL);\n const getHeaders = () =>\n withUserAgentSuffix(\n {\n Authorization: `Bearer ${loadApiKey({\n apiKey: options.apiKey,\n environmentVariableName: 'LUMA_API_KEY',\n description: 'Luma',\n })}`,\n ...options.headers,\n },\n `ai-sdk/luma/${VERSION}`,\n );\n\n const createImageModel = (modelId: LumaImageModelId) =>\n new LumaImageModel(modelId, {\n provider: 'luma.image',\n baseURL: baseURL ?? defaultBaseURL,\n headers: getHeaders,\n fetch: options.fetch,\n });\n\n const embeddingModel = (modelId: string) => {\n throw new NoSuchModelError({\n modelId,\n modelType: 'embeddingModel',\n });\n };\n\n return {\n specificationVersion: 'v3' as const,\n image: createImageModel,\n imageModel: createImageModel,\n languageModel: (modelId: string) => {\n throw new NoSuchModelError({\n modelId,\n modelType: 'languageModel',\n });\n },\n embeddingModel,\n textEmbeddingModel: embeddingModel,\n };\n}\n\nexport const luma = createLuma();\n","import {\n ImageModelV3,\n ImageModelV3File,\n SharedV3Warning,\n InvalidResponseDataError,\n} from '@ai-sdk/provider';\nimport {\n FetchFunction,\n combineHeaders,\n createBinaryResponseHandler,\n createJsonResponseHandler,\n createJsonErrorResponseHandler,\n createStatusCodeErrorResponseHandler,\n delay,\n getFromApi,\n postJsonToApi,\n InferSchema,\n lazySchema,\n parseProviderOptions,\n zodSchema,\n} from '@ai-sdk/provider-utils';\nimport { LumaImageSettings, LumaReferenceType } from './luma-image-settings';\nimport { z } from 'zod/v4';\n\nconst DEFAULT_POLL_INTERVAL_MILLIS = 500;\nconst DEFAULT_MAX_POLL_ATTEMPTS = 60000 / DEFAULT_POLL_INTERVAL_MILLIS;\n\ninterface LumaImageModelConfig {\n provider: string;\n baseURL: string;\n headers: () => Record<string, string>;\n fetch?: FetchFunction;\n _internal?: {\n currentDate?: () => Date;\n };\n}\n\nexport class LumaImageModel implements ImageModelV3 {\n readonly specificationVersion = 'v3';\n readonly maxImagesPerCall = 1;\n readonly pollIntervalMillis = DEFAULT_POLL_INTERVAL_MILLIS;\n readonly maxPollAttempts = DEFAULT_MAX_POLL_ATTEMPTS;\n\n get provider(): string {\n return this.config.provider;\n }\n\n constructor(\n readonly modelId: string,\n private readonly config: LumaImageModelConfig,\n ) {}\n\n async doGenerate({\n prompt,\n n,\n size,\n aspectRatio,\n seed,\n providerOptions,\n headers,\n abortSignal,\n files,\n mask,\n }: Parameters<ImageModelV3['doGenerate']>[0]): Promise<\n Awaited<ReturnType<ImageModelV3['doGenerate']>>\n > {\n const warnings: Array<SharedV3Warning> = [];\n\n if (seed != null) {\n warnings.push({\n type: 'unsupported',\n feature: 'seed',\n details: 'This model does not support the `seed` option.',\n });\n }\n\n if (size != null) {\n warnings.push({\n type: 'unsupported',\n feature: 'size',\n details:\n 'This model does not support the `size` option. Use `aspectRatio` instead.',\n });\n }\n\n // Parse and validate provider options\n const lumaOptions = await parseProviderOptions({\n provider: 'luma',\n providerOptions,\n schema: lumaImageProviderOptionsSchema,\n });\n\n // Extract non-request options\n const {\n pollIntervalMillis,\n maxPollAttempts,\n referenceType,\n images: imageConfigs,\n ...providerRequestOptions\n } = lumaOptions ?? {};\n\n // Handle image editing via files with reference type support\n const editingOptions = this.getEditingOptions(\n files,\n mask,\n referenceType ?? undefined,\n imageConfigs ?? [],\n );\n\n const currentDate = this.config._internal?.currentDate?.() ?? new Date();\n const fullHeaders = combineHeaders(this.config.headers(), headers);\n const { value: generationResponse, responseHeaders } = await postJsonToApi({\n url: this.getLumaGenerationsUrl(),\n headers: fullHeaders,\n body: {\n prompt,\n ...(aspectRatio ? { aspect_ratio: aspectRatio } : {}),\n model: this.modelId,\n ...editingOptions,\n ...providerRequestOptions,\n },\n abortSignal,\n fetch: this.config.fetch,\n failedResponseHandler: this.createLumaErrorHandler(),\n successfulResponseHandler: createJsonResponseHandler(\n lumaGenerationResponseSchema,\n ),\n });\n\n const imageUrl = await this.pollForImageUrl(\n generationResponse.id,\n fullHeaders,\n abortSignal,\n {\n pollIntervalMillis: pollIntervalMillis ?? undefined,\n maxPollAttempts: maxPollAttempts ?? undefined,\n },\n );\n\n const downloadedImage = await this.downloadImage(imageUrl, abortSignal);\n\n return {\n images: [downloadedImage],\n warnings,\n response: {\n modelId: this.modelId,\n timestamp: currentDate,\n headers: responseHeaders,\n },\n };\n }\n\n private async pollForImageUrl(\n generationId: string,\n headers: Record<string, string | undefined>,\n abortSignal: AbortSignal | undefined,\n pollSettings?: { pollIntervalMillis?: number; maxPollAttempts?: number },\n ): Promise<string> {\n const url = this.getLumaGenerationsUrl(generationId);\n const maxPollAttempts =\n pollSettings?.maxPollAttempts ?? this.maxPollAttempts;\n const pollIntervalMillis =\n pollSettings?.pollIntervalMillis ?? this.pollIntervalMillis;\n\n for (let i = 0; i < maxPollAttempts; i++) {\n const { value: statusResponse } = await getFromApi({\n url,\n headers,\n abortSignal,\n fetch: this.config.fetch,\n failedResponseHandler: this.createLumaErrorHandler(),\n successfulResponseHandler: createJsonResponseHandler(\n lumaGenerationResponseSchema,\n ),\n });\n\n switch (statusResponse.state) {\n case 'completed':\n if (!statusResponse.assets?.image) {\n throw new InvalidResponseDataError({\n data: statusResponse,\n message: `Image generation completed but no image was found.`,\n });\n }\n return statusResponse.assets.image;\n case 'failed':\n throw new InvalidResponseDataError({\n data: statusResponse,\n message: `Image generation failed.`,\n });\n }\n await delay(pollIntervalMillis);\n }\n\n throw new Error(\n `Image generation timed out after ${this.maxPollAttempts} attempts.`,\n );\n }\n\n private createLumaErrorHandler() {\n return createJsonErrorResponseHandler({\n errorSchema: lumaErrorSchema,\n errorToMessage: (error: LumaErrorData) =>\n error.detail[0].msg ?? 'Unknown error',\n });\n }\n\n private getEditingOptions(\n files: ImageModelV3File[] | undefined,\n mask: ImageModelV3File | undefined,\n referenceType: LumaReferenceType = 'image',\n imageConfigs: Array<{ weight?: number | null; id?: string | null }> = [],\n ): Record<string, unknown> {\n const options: Record<string, unknown> = {};\n\n // Luma does not support mask-based inpainting\n if (mask != null) {\n throw new Error(\n 'Luma AI does not support mask-based image editing. ' +\n 'Use the prompt to describe the changes you want to make, along with ' +\n '`prompt.images` containing the source image URL.',\n );\n }\n\n if (files == null || files.length === 0) {\n return options;\n }\n\n // Validate all files are URL-based\n for (const file of files) {\n if (file.type !== 'url') {\n throw new Error(\n 'Luma AI only supports URL-based images. ' +\n 'Please provide image URLs using `prompt.images` with publicly accessible URLs. ' +\n 'Base64 and Uint8Array data are not supported.',\n );\n }\n }\n\n // Default weights per reference type\n const defaultWeights: Record<LumaReferenceType, number> = {\n image: 0.85,\n style: 0.8,\n character: 1.0, // Not used, but defined for completeness\n modify_image: 1.0,\n };\n\n switch (referenceType) {\n case 'image': {\n // Supports up to 4 images\n if (files.length > 4) {\n throw new Error(\n 'Luma AI image supports up to 4 reference images. ' +\n `You provided ${files.length} images.`,\n );\n }\n options.image = files.map((file, index) => ({\n url: (file as { type: 'url'; url: string }).url,\n weight: imageConfigs[index]?.weight ?? defaultWeights.image,\n }));\n break;\n }\n\n case 'style': {\n // Style ref accepts an array but typically uses one style image\n options.style = files.map((file, index) => ({\n url: (file as { type: 'url'; url: string }).url,\n weight: imageConfigs[index]?.weight ?? defaultWeights.style,\n }));\n break;\n }\n\n case 'character': {\n // Group images by identity id\n const identities: Record<string, string[]> = {};\n for (let i = 0; i < files.length; i++) {\n const file = files[i] as { type: 'url'; url: string };\n const identityId = imageConfigs[i]?.id ?? 'identity0';\n if (!identities[identityId]) {\n identities[identityId] = [];\n }\n identities[identityId].push(file.url);\n }\n\n // Validate each identity has at most 4 images\n for (const [identityId, images] of Object.entries(identities)) {\n if (images.length > 4) {\n throw new Error(\n `Luma AI character supports up to 4 images per identity. ` +\n `Identity '${identityId}' has ${images.length} images.`,\n );\n }\n }\n\n options.character = Object.fromEntries(\n Object.entries(identities).map(([id, images]) => [id, { images }]),\n );\n break;\n }\n\n case 'modify_image': {\n // Only supports a single image\n if (files.length > 1) {\n throw new Error(\n 'Luma AI modify_image only supports a single input image. ' +\n `You provided ${files.length} images.`,\n );\n }\n options.modify_image = {\n url: (files[0] as { type: 'url'; url: string }).url,\n weight: imageConfigs[0]?.weight ?? defaultWeights.modify_image,\n };\n break;\n }\n }\n\n return options;\n }\n\n private getLumaGenerationsUrl(generationId?: string) {\n return `${this.config.baseURL}/dream-machine/v1/generations/${\n generationId ?? 'image'\n }`;\n }\n\n private async downloadImage(\n url: string,\n abortSignal: AbortSignal | undefined,\n ): Promise<Uint8Array> {\n const { value: response } = await getFromApi({\n url,\n // No specific headers should be needed for this request as it's a\n // generated image provided by Luma.\n abortSignal,\n failedResponseHandler: createStatusCodeErrorResponseHandler(),\n successfulResponseHandler: createBinaryResponseHandler(),\n fetch: this.config.fetch,\n });\n return response;\n }\n}\n\n// limited version of the schema, focussed on what is needed for the implementation\n// this approach limits breakages when the API changes and increases efficiency\nconst lumaGenerationResponseSchema = lazySchema(() =>\n zodSchema(\n z.object({\n id: z.string(),\n state: z.enum(['queued', 'dreaming', 'completed', 'failed']),\n failure_reason: z.string().nullish(),\n assets: z\n .object({\n image: z.string(), // URL of the generated image\n })\n .nullish(),\n }),\n ),\n);\n\nconst lumaErrorSchema = z.object({\n detail: z.array(\n z.object({\n type: z.string(),\n loc: z.array(z.string()),\n msg: z.string(),\n input: z.string(),\n ctx: z\n .object({\n expected: z.string(),\n })\n .nullish(),\n }),\n ),\n});\n\nexport type LumaErrorData = z.infer<typeof lumaErrorSchema>;\n\n/**\n * Provider options schema for Luma image generation.\n *\n * @see https://docs.lumalabs.ai/docs/image-generation\n */\nexport const lumaImageProviderOptionsSchema = lazySchema(() =>\n zodSchema(\n z\n .object({\n /**\n * The type of image reference to use when providing input images.\n * - `image`: Guide generation using reference images (up to 4). Default.\n * - `style`: Apply a specific style from reference image(s).\n * - `character`: Create consistent characters from reference images (up to 4).\n * - `modify_image`: Transform a single input image with prompt guidance.\n */\n referenceType: z\n .enum(['image', 'style', 'character', 'modify_image'])\n .nullish(),\n\n /**\n * Per-image configuration array. Each entry corresponds to an image in `prompt.images`.\n * Allows setting individual weights for each reference image.\n */\n images: z\n .array(\n z.object({\n /**\n * The weight of this image's influence on the generation.\n * - For `image`: Higher weight = closer to reference (default: 0.85)\n * - For `style`: Higher weight = stronger style influence (default: 0.8)\n * - For `modify_image`: Higher weight = closer to input, lower = more creative (default: 1.0)\n */\n weight: z.number().min(0).max(1).nullish(),\n\n /**\n * The identity name for character references.\n * Used with `character` to specify which identity group the image belongs to.\n * Luma supports multiple identities (e.g., 'identity0', 'identity1') for generating\n * images with multiple consistent characters.\n * Default: 'identity0'\n */\n id: z.string().nullish(),\n }),\n )\n .nullish(),\n\n /**\n * Override the polling interval in milliseconds (default 500).\n */\n pollIntervalMillis: z.number().nullish(),\n\n /**\n * Override the maximum number of polling attempts (default 120).\n */\n maxPollAttempts: z.number().nullish(),\n })\n .passthrough(),\n ),\n);\n\nexport type LumaImageProviderOptions = InferSchema<\n typeof lumaImageProviderOptionsSchema\n>;\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,mBAA2D;AAC3D,IAAAC,yBAKO;;;ACNP,sBAKO;AACP,4BAcO;AAEP,gBAAkB;AAElB,IAAM,+BAA+B;AACrC,IAAM,4BAA4B,MAAQ;AAYnC,IAAM,iBAAN,MAA6C;AAAA,EAUlD,YACW,SACQ,QACjB;AAFS;AACQ;AAXnB,SAAS,uBAAuB;AAChC,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB;AAAA,EASxB;AAAA,EAPH,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CAAC;AAAA,IACH;AAAA,IACA;AAAA,IACA,oBAAoB;AAAA,EACtB;AACF;AAEO,IAAM,OAAO,WAAW;","names":["import_provider","import_provider_utils","_a","_b"]}
|
package/dist/index.mjs
CHANGED
|
@@ -18,7 +18,10 @@ import {
|
|
|
18
18
|
createStatusCodeErrorResponseHandler,
|
|
19
19
|
delay,
|
|
20
20
|
getFromApi,
|
|
21
|
-
postJsonToApi
|
|
21
|
+
postJsonToApi,
|
|
22
|
+
lazySchema,
|
|
23
|
+
parseProviderOptions,
|
|
24
|
+
zodSchema
|
|
22
25
|
} from "@ai-sdk/provider-utils";
|
|
23
26
|
import { z } from "zod/v4";
|
|
24
27
|
var DEFAULT_POLL_INTERVAL_MILLIS = 500;
|
|
@@ -43,9 +46,11 @@ var LumaImageModel = class {
|
|
|
43
46
|
seed,
|
|
44
47
|
providerOptions,
|
|
45
48
|
headers,
|
|
46
|
-
abortSignal
|
|
49
|
+
abortSignal,
|
|
50
|
+
files,
|
|
51
|
+
mask
|
|
47
52
|
}) {
|
|
48
|
-
var _a, _b, _c
|
|
53
|
+
var _a, _b, _c;
|
|
49
54
|
const warnings = [];
|
|
50
55
|
if (seed != null) {
|
|
51
56
|
warnings.push({
|
|
@@ -61,8 +66,25 @@ var LumaImageModel = class {
|
|
|
61
66
|
details: "This model does not support the `size` option. Use `aspectRatio` instead."
|
|
62
67
|
});
|
|
63
68
|
}
|
|
64
|
-
const
|
|
65
|
-
|
|
69
|
+
const lumaOptions = await parseProviderOptions({
|
|
70
|
+
provider: "luma",
|
|
71
|
+
providerOptions,
|
|
72
|
+
schema: lumaImageProviderOptionsSchema
|
|
73
|
+
});
|
|
74
|
+
const {
|
|
75
|
+
pollIntervalMillis,
|
|
76
|
+
maxPollAttempts,
|
|
77
|
+
referenceType,
|
|
78
|
+
images: imageConfigs,
|
|
79
|
+
...providerRequestOptions
|
|
80
|
+
} = lumaOptions != null ? lumaOptions : {};
|
|
81
|
+
const editingOptions = this.getEditingOptions(
|
|
82
|
+
files,
|
|
83
|
+
mask,
|
|
84
|
+
referenceType != null ? referenceType : void 0,
|
|
85
|
+
imageConfigs != null ? imageConfigs : []
|
|
86
|
+
);
|
|
87
|
+
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
66
88
|
const fullHeaders = combineHeaders(this.config.headers(), headers);
|
|
67
89
|
const { value: generationResponse, responseHeaders } = await postJsonToApi({
|
|
68
90
|
url: this.getLumaGenerationsUrl(),
|
|
@@ -71,6 +93,7 @@ var LumaImageModel = class {
|
|
|
71
93
|
prompt,
|
|
72
94
|
...aspectRatio ? { aspect_ratio: aspectRatio } : {},
|
|
73
95
|
model: this.modelId,
|
|
96
|
+
...editingOptions,
|
|
74
97
|
...providerRequestOptions
|
|
75
98
|
},
|
|
76
99
|
abortSignal,
|
|
@@ -84,7 +107,10 @@ var LumaImageModel = class {
|
|
|
84
107
|
generationResponse.id,
|
|
85
108
|
fullHeaders,
|
|
86
109
|
abortSignal,
|
|
87
|
-
|
|
110
|
+
{
|
|
111
|
+
pollIntervalMillis: pollIntervalMillis != null ? pollIntervalMillis : void 0,
|
|
112
|
+
maxPollAttempts: maxPollAttempts != null ? maxPollAttempts : void 0
|
|
113
|
+
}
|
|
88
114
|
);
|
|
89
115
|
const downloadedImage = await this.downloadImage(imageUrl, abortSignal);
|
|
90
116
|
return {
|
|
@@ -97,11 +123,11 @@ var LumaImageModel = class {
|
|
|
97
123
|
}
|
|
98
124
|
};
|
|
99
125
|
}
|
|
100
|
-
async pollForImageUrl(generationId, headers, abortSignal,
|
|
126
|
+
async pollForImageUrl(generationId, headers, abortSignal, pollSettings) {
|
|
101
127
|
var _a, _b, _c;
|
|
102
128
|
const url = this.getLumaGenerationsUrl(generationId);
|
|
103
|
-
const maxPollAttempts = (_a =
|
|
104
|
-
const pollIntervalMillis = (_b =
|
|
129
|
+
const maxPollAttempts = (_a = pollSettings == null ? void 0 : pollSettings.maxPollAttempts) != null ? _a : this.maxPollAttempts;
|
|
130
|
+
const pollIntervalMillis = (_b = pollSettings == null ? void 0 : pollSettings.pollIntervalMillis) != null ? _b : this.pollIntervalMillis;
|
|
105
131
|
for (let i = 0; i < maxPollAttempts; i++) {
|
|
106
132
|
const { value: statusResponse } = await getFromApi({
|
|
107
133
|
url,
|
|
@@ -143,6 +169,94 @@ var LumaImageModel = class {
|
|
|
143
169
|
}
|
|
144
170
|
});
|
|
145
171
|
}
|
|
172
|
+
getEditingOptions(files, mask, referenceType = "image", imageConfigs = []) {
|
|
173
|
+
var _a, _b, _c, _d;
|
|
174
|
+
const options = {};
|
|
175
|
+
if (mask != null) {
|
|
176
|
+
throw new Error(
|
|
177
|
+
"Luma AI does not support mask-based image editing. Use the prompt to describe the changes you want to make, along with `prompt.images` containing the source image URL."
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
if (files == null || files.length === 0) {
|
|
181
|
+
return options;
|
|
182
|
+
}
|
|
183
|
+
for (const file of files) {
|
|
184
|
+
if (file.type !== "url") {
|
|
185
|
+
throw new Error(
|
|
186
|
+
"Luma AI only supports URL-based images. Please provide image URLs using `prompt.images` with publicly accessible URLs. Base64 and Uint8Array data are not supported."
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
const defaultWeights = {
|
|
191
|
+
image: 0.85,
|
|
192
|
+
style: 0.8,
|
|
193
|
+
character: 1,
|
|
194
|
+
// Not used, but defined for completeness
|
|
195
|
+
modify_image: 1
|
|
196
|
+
};
|
|
197
|
+
switch (referenceType) {
|
|
198
|
+
case "image": {
|
|
199
|
+
if (files.length > 4) {
|
|
200
|
+
throw new Error(
|
|
201
|
+
`Luma AI image supports up to 4 reference images. You provided ${files.length} images.`
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
options.image = files.map((file, index) => {
|
|
205
|
+
var _a2, _b2;
|
|
206
|
+
return {
|
|
207
|
+
url: file.url,
|
|
208
|
+
weight: (_b2 = (_a2 = imageConfigs[index]) == null ? void 0 : _a2.weight) != null ? _b2 : defaultWeights.image
|
|
209
|
+
};
|
|
210
|
+
});
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
case "style": {
|
|
214
|
+
options.style = files.map((file, index) => {
|
|
215
|
+
var _a2, _b2;
|
|
216
|
+
return {
|
|
217
|
+
url: file.url,
|
|
218
|
+
weight: (_b2 = (_a2 = imageConfigs[index]) == null ? void 0 : _a2.weight) != null ? _b2 : defaultWeights.style
|
|
219
|
+
};
|
|
220
|
+
});
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
case "character": {
|
|
224
|
+
const identities = {};
|
|
225
|
+
for (let i = 0; i < files.length; i++) {
|
|
226
|
+
const file = files[i];
|
|
227
|
+
const identityId = (_b = (_a = imageConfigs[i]) == null ? void 0 : _a.id) != null ? _b : "identity0";
|
|
228
|
+
if (!identities[identityId]) {
|
|
229
|
+
identities[identityId] = [];
|
|
230
|
+
}
|
|
231
|
+
identities[identityId].push(file.url);
|
|
232
|
+
}
|
|
233
|
+
for (const [identityId, images] of Object.entries(identities)) {
|
|
234
|
+
if (images.length > 4) {
|
|
235
|
+
throw new Error(
|
|
236
|
+
`Luma AI character supports up to 4 images per identity. Identity '${identityId}' has ${images.length} images.`
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
options.character = Object.fromEntries(
|
|
241
|
+
Object.entries(identities).map(([id, images]) => [id, { images }])
|
|
242
|
+
);
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
case "modify_image": {
|
|
246
|
+
if (files.length > 1) {
|
|
247
|
+
throw new Error(
|
|
248
|
+
`Luma AI modify_image only supports a single input image. You provided ${files.length} images.`
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
options.modify_image = {
|
|
252
|
+
url: files[0].url,
|
|
253
|
+
weight: (_d = (_c = imageConfigs[0]) == null ? void 0 : _c.weight) != null ? _d : defaultWeights.modify_image
|
|
254
|
+
};
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return options;
|
|
259
|
+
}
|
|
146
260
|
getLumaGenerationsUrl(generationId) {
|
|
147
261
|
return `${this.config.baseURL}/dream-machine/v1/generations/${generationId != null ? generationId : "image"}`;
|
|
148
262
|
}
|
|
@@ -159,15 +273,19 @@ var LumaImageModel = class {
|
|
|
159
273
|
return response;
|
|
160
274
|
}
|
|
161
275
|
};
|
|
162
|
-
var lumaGenerationResponseSchema =
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
276
|
+
var lumaGenerationResponseSchema = lazySchema(
|
|
277
|
+
() => zodSchema(
|
|
278
|
+
z.object({
|
|
279
|
+
id: z.string(),
|
|
280
|
+
state: z.enum(["queued", "dreaming", "completed", "failed"]),
|
|
281
|
+
failure_reason: z.string().nullish(),
|
|
282
|
+
assets: z.object({
|
|
283
|
+
image: z.string()
|
|
284
|
+
// URL of the generated image
|
|
285
|
+
}).nullish()
|
|
286
|
+
})
|
|
287
|
+
)
|
|
288
|
+
);
|
|
171
289
|
var lumaErrorSchema = z.object({
|
|
172
290
|
detail: z.array(
|
|
173
291
|
z.object({
|
|
@@ -181,9 +299,54 @@ var lumaErrorSchema = z.object({
|
|
|
181
299
|
})
|
|
182
300
|
)
|
|
183
301
|
});
|
|
302
|
+
var lumaImageProviderOptionsSchema = lazySchema(
|
|
303
|
+
() => zodSchema(
|
|
304
|
+
z.object({
|
|
305
|
+
/**
|
|
306
|
+
* The type of image reference to use when providing input images.
|
|
307
|
+
* - `image`: Guide generation using reference images (up to 4). Default.
|
|
308
|
+
* - `style`: Apply a specific style from reference image(s).
|
|
309
|
+
* - `character`: Create consistent characters from reference images (up to 4).
|
|
310
|
+
* - `modify_image`: Transform a single input image with prompt guidance.
|
|
311
|
+
*/
|
|
312
|
+
referenceType: z.enum(["image", "style", "character", "modify_image"]).nullish(),
|
|
313
|
+
/**
|
|
314
|
+
* Per-image configuration array. Each entry corresponds to an image in `prompt.images`.
|
|
315
|
+
* Allows setting individual weights for each reference image.
|
|
316
|
+
*/
|
|
317
|
+
images: z.array(
|
|
318
|
+
z.object({
|
|
319
|
+
/**
|
|
320
|
+
* The weight of this image's influence on the generation.
|
|
321
|
+
* - For `image`: Higher weight = closer to reference (default: 0.85)
|
|
322
|
+
* - For `style`: Higher weight = stronger style influence (default: 0.8)
|
|
323
|
+
* - For `modify_image`: Higher weight = closer to input, lower = more creative (default: 1.0)
|
|
324
|
+
*/
|
|
325
|
+
weight: z.number().min(0).max(1).nullish(),
|
|
326
|
+
/**
|
|
327
|
+
* The identity name for character references.
|
|
328
|
+
* Used with `character` to specify which identity group the image belongs to.
|
|
329
|
+
* Luma supports multiple identities (e.g., 'identity0', 'identity1') for generating
|
|
330
|
+
* images with multiple consistent characters.
|
|
331
|
+
* Default: 'identity0'
|
|
332
|
+
*/
|
|
333
|
+
id: z.string().nullish()
|
|
334
|
+
})
|
|
335
|
+
).nullish(),
|
|
336
|
+
/**
|
|
337
|
+
* Override the polling interval in milliseconds (default 500).
|
|
338
|
+
*/
|
|
339
|
+
pollIntervalMillis: z.number().nullish(),
|
|
340
|
+
/**
|
|
341
|
+
* Override the maximum number of polling attempts (default 120).
|
|
342
|
+
*/
|
|
343
|
+
maxPollAttempts: z.number().nullish()
|
|
344
|
+
}).passthrough()
|
|
345
|
+
)
|
|
346
|
+
);
|
|
184
347
|
|
|
185
348
|
// src/version.ts
|
|
186
|
-
var VERSION = true ? "2.0.0-beta.
|
|
349
|
+
var VERSION = true ? "2.0.0-beta.55" : "0.0.0-test";
|
|
187
350
|
|
|
188
351
|
// src/luma-provider.ts
|
|
189
352
|
var defaultBaseURL = "https://api.lumalabs.ai";
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/luma-provider.ts","../src/luma-image-model.ts","../src/version.ts"],"sourcesContent":["import { ImageModelV3, NoSuchModelError, ProviderV3 } from '@ai-sdk/provider';\nimport {\n FetchFunction,\n loadApiKey,\n withoutTrailingSlash,\n withUserAgentSuffix,\n} from '@ai-sdk/provider-utils';\nimport { LumaImageModel } from './luma-image-model';\nimport { LumaImageModelId } from './luma-image-settings';\nimport { VERSION } from './version';\n\nexport interface LumaProviderSettings {\n /**\nLuma API key. Default value is taken from the `LUMA_API_KEY` environment\nvariable.\n */\n apiKey?: string;\n /**\nBase URL for the API calls.\n */\n baseURL?: string;\n /**\nCustom headers to include in the requests.\n */\n headers?: Record<string, string>;\n /**\nCustom fetch implementation. You can use it as a middleware to intercept requests,\nor to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\nexport interface LumaProvider extends ProviderV3 {\n /**\nCreates a model for image generation.\n */\n image(modelId: LumaImageModelId): ImageModelV3;\n\n /**\nCreates a model for image generation.\n */\n imageModel(modelId: LumaImageModelId): ImageModelV3;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(modelId: string): never;\n}\n\nconst defaultBaseURL = 'https://api.lumalabs.ai';\n\nexport function createLuma(options: LumaProviderSettings = {}): LumaProvider {\n const baseURL = withoutTrailingSlash(options.baseURL ?? defaultBaseURL);\n const getHeaders = () =>\n withUserAgentSuffix(\n {\n Authorization: `Bearer ${loadApiKey({\n apiKey: options.apiKey,\n environmentVariableName: 'LUMA_API_KEY',\n description: 'Luma',\n })}`,\n ...options.headers,\n },\n `ai-sdk/luma/${VERSION}`,\n );\n\n const createImageModel = (modelId: LumaImageModelId) =>\n new LumaImageModel(modelId, {\n provider: 'luma.image',\n baseURL: baseURL ?? defaultBaseURL,\n headers: getHeaders,\n fetch: options.fetch,\n });\n\n const embeddingModel = (modelId: string) => {\n throw new NoSuchModelError({\n modelId,\n modelType: 'embeddingModel',\n });\n };\n\n return {\n specificationVersion: 'v3' as const,\n image: createImageModel,\n imageModel: createImageModel,\n languageModel: (modelId: string) => {\n throw new NoSuchModelError({\n modelId,\n modelType: 'languageModel',\n });\n },\n embeddingModel,\n textEmbeddingModel: embeddingModel,\n };\n}\n\nexport const luma = createLuma();\n","import {\n ImageModelV3,\n SharedV3Warning,\n InvalidResponseDataError,\n} from '@ai-sdk/provider';\nimport {\n FetchFunction,\n combineHeaders,\n createBinaryResponseHandler,\n createJsonResponseHandler,\n createJsonErrorResponseHandler,\n createStatusCodeErrorResponseHandler,\n delay,\n getFromApi,\n postJsonToApi,\n} from '@ai-sdk/provider-utils';\nimport { LumaImageSettings } from './luma-image-settings';\nimport { z } from 'zod/v4';\n\nconst DEFAULT_POLL_INTERVAL_MILLIS = 500;\nconst DEFAULT_MAX_POLL_ATTEMPTS = 60000 / DEFAULT_POLL_INTERVAL_MILLIS;\n\ninterface LumaImageModelConfig {\n provider: string;\n baseURL: string;\n headers: () => Record<string, string>;\n fetch?: FetchFunction;\n _internal?: {\n currentDate?: () => Date;\n };\n}\n\nexport class LumaImageModel implements ImageModelV3 {\n readonly specificationVersion = 'v3';\n readonly maxImagesPerCall = 1;\n readonly pollIntervalMillis = DEFAULT_POLL_INTERVAL_MILLIS;\n readonly maxPollAttempts = DEFAULT_MAX_POLL_ATTEMPTS;\n\n get provider(): string {\n return this.config.provider;\n }\n\n constructor(\n readonly modelId: string,\n private readonly config: LumaImageModelConfig,\n ) {}\n\n async doGenerate({\n prompt,\n n,\n size,\n aspectRatio,\n seed,\n providerOptions,\n headers,\n abortSignal,\n }: Parameters<ImageModelV3['doGenerate']>[0]): Promise<\n Awaited<ReturnType<ImageModelV3['doGenerate']>>\n > {\n const warnings: Array<SharedV3Warning> = [];\n\n if (seed != null) {\n warnings.push({\n type: 'unsupported',\n feature: 'seed',\n details: 'This model does not support the `seed` option.',\n });\n }\n\n if (size != null) {\n warnings.push({\n type: 'unsupported',\n feature: 'size',\n details:\n 'This model does not support the `size` option. Use `aspectRatio` instead.',\n });\n }\n\n // remove non-request options from providerOptions\n const { pollIntervalMillis, maxPollAttempts, ...providerRequestOptions } =\n providerOptions.luma ?? {};\n\n const currentDate = this.config._internal?.currentDate?.() ?? new Date();\n const fullHeaders = combineHeaders(this.config.headers(), headers);\n const { value: generationResponse, responseHeaders } = await postJsonToApi({\n url: this.getLumaGenerationsUrl(),\n headers: fullHeaders,\n body: {\n prompt,\n ...(aspectRatio ? { aspect_ratio: aspectRatio } : {}),\n model: this.modelId,\n ...providerRequestOptions,\n },\n abortSignal,\n fetch: this.config.fetch,\n failedResponseHandler: this.createLumaErrorHandler(),\n successfulResponseHandler: createJsonResponseHandler(\n lumaGenerationResponseSchema,\n ),\n });\n\n const imageUrl = await this.pollForImageUrl(\n generationResponse.id,\n fullHeaders,\n abortSignal,\n providerOptions.luma,\n );\n\n const downloadedImage = await this.downloadImage(imageUrl, abortSignal);\n\n return {\n images: [downloadedImage],\n warnings,\n response: {\n modelId: this.modelId,\n timestamp: currentDate,\n headers: responseHeaders,\n },\n };\n }\n\n private async pollForImageUrl(\n generationId: string,\n headers: Record<string, string | undefined>,\n abortSignal: AbortSignal | undefined,\n imageSettings?: LumaImageSettings,\n ): Promise<string> {\n const url = this.getLumaGenerationsUrl(generationId);\n const maxPollAttempts =\n imageSettings?.maxPollAttempts ?? this.maxPollAttempts;\n const pollIntervalMillis =\n imageSettings?.pollIntervalMillis ?? this.pollIntervalMillis;\n\n for (let i = 0; i < maxPollAttempts; i++) {\n const { value: statusResponse } = await getFromApi({\n url,\n headers,\n abortSignal,\n fetch: this.config.fetch,\n failedResponseHandler: this.createLumaErrorHandler(),\n successfulResponseHandler: createJsonResponseHandler(\n lumaGenerationResponseSchema,\n ),\n });\n\n switch (statusResponse.state) {\n case 'completed':\n if (!statusResponse.assets?.image) {\n throw new InvalidResponseDataError({\n data: statusResponse,\n message: `Image generation completed but no image was found.`,\n });\n }\n return statusResponse.assets.image;\n case 'failed':\n throw new InvalidResponseDataError({\n data: statusResponse,\n message: `Image generation failed.`,\n });\n }\n await delay(pollIntervalMillis);\n }\n\n throw new Error(\n `Image generation timed out after ${this.maxPollAttempts} attempts.`,\n );\n }\n\n private createLumaErrorHandler() {\n return createJsonErrorResponseHandler({\n errorSchema: lumaErrorSchema,\n errorToMessage: (error: LumaErrorData) =>\n error.detail[0].msg ?? 'Unknown error',\n });\n }\n\n private getLumaGenerationsUrl(generationId?: string) {\n return `${this.config.baseURL}/dream-machine/v1/generations/${\n generationId ?? 'image'\n }`;\n }\n\n private async downloadImage(\n url: string,\n abortSignal: AbortSignal | undefined,\n ): Promise<Uint8Array> {\n const { value: response } = await getFromApi({\n url,\n // No specific headers should be needed for this request as it's a\n // generated image provided by Luma.\n abortSignal,\n failedResponseHandler: createStatusCodeErrorResponseHandler(),\n successfulResponseHandler: createBinaryResponseHandler(),\n fetch: this.config.fetch,\n });\n return response;\n }\n}\n\n// limited version of the schema, focussed on what is needed for the implementation\n// this approach limits breakages when the API changes and increases efficiency\nconst lumaGenerationResponseSchema = z.object({\n id: z.string(),\n state: z.enum(['queued', 'dreaming', 'completed', 'failed']),\n failure_reason: z.string().nullish(),\n assets: z\n .object({\n image: z.string(), // URL of the generated image\n })\n .nullish(),\n});\n\nconst lumaErrorSchema = z.object({\n detail: z.array(\n z.object({\n type: z.string(),\n loc: z.array(z.string()),\n msg: z.string(),\n input: z.string(),\n ctx: z\n .object({\n expected: z.string(),\n })\n .nullish(),\n }),\n ),\n});\n\nexport type LumaErrorData = z.infer<typeof lumaErrorSchema>;\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n"],"mappings":";AAAA,SAAuB,wBAAoC;AAC3D;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACNP;AAAA,EAGE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,E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AM,iBAAiB;AAEhB,SAAS,WAAW,UAAgC,CAAC,GAAiB;AAnD7E;AAoDE,QAAM,UAAU,sBAAqB,aAAQ,YAAR,YAAmB,cAAc;AACtE,QAAM,aAAa,MACjB;AAAA,IACE;AAAA,MACE,eAAe,UAAU,WAAW;AAAA,QAClC,QAAQ,QAAQ;AAAA,QAChB,yBAAyB;AAAA,QACzB,aAAa;AAAA,MACf,CAAC,CAAC;AAAA,MACF,GAAG,QAAQ;AAAA,IACb;AAAA,IACA,eAAe,OAAO;AAAA,EACxB;AAEF,QAAM,mBAAmB,CAAC,YACxB,IAAI,eAAe,SAAS;AAAA,IAC1B,UAAU;AAAA,IACV,SAAS,4BAAW;AAAA,IACpB,SAAS;AAAA,IACT,OAAO,QAAQ;AAAA,EACjB,CAAC;AAEH,QAAM,iBAAiB,CAAC,YAAoB;AAC1C,UAAM,IAAI,iBAAiB;AAAA,MACzB;AAAA,MACA,WAAW;AAAA,IACb,CAAC;AAAA,EACH;AAEA,SAAO;AAAA,IACL,sBAAsB;AAAA,IACtB,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,eAAe,CAAC,YAAoB;AAClC,YAAM,IAAI,iBAAiB;AAAA,QACzB;AAAA,QACA,WAAW;AAAA,MACb,CAAC;AAAA,IACH;AAAA,IACA;AAAA,IACA,oBAAoB;AAAA,EACtB;AACF;AAEO,IAAM,OAAO,WAAW;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/luma-provider.ts","../src/luma-image-model.ts","../src/version.ts"],"sourcesContent":["import { ImageModelV3, NoSuchModelError, ProviderV3 } from '@ai-sdk/provider';\nimport {\n FetchFunction,\n loadApiKey,\n withoutTrailingSlash,\n withUserAgentSuffix,\n} from '@ai-sdk/provider-utils';\nimport { LumaImageModel } from './luma-image-model';\nimport { LumaImageModelId } from './luma-image-settings';\nimport { VERSION } from './version';\n\nexport interface LumaProviderSettings {\n /**\nLuma API key. Default value is taken from the `LUMA_API_KEY` environment\nvariable.\n */\n apiKey?: string;\n /**\nBase URL for the API calls.\n */\n baseURL?: string;\n /**\nCustom headers to include in the requests.\n */\n headers?: Record<string, string>;\n /**\nCustom fetch implementation. You can use it as a middleware to intercept requests,\nor to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\nexport interface LumaProvider extends ProviderV3 {\n /**\nCreates a model for image generation.\n */\n image(modelId: LumaImageModelId): ImageModelV3;\n\n /**\nCreates a model for image generation.\n */\n imageModel(modelId: LumaImageModelId): ImageModelV3;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(modelId: string): never;\n}\n\nconst defaultBaseURL = 'https://api.lumalabs.ai';\n\nexport function createLuma(options: LumaProviderSettings = {}): LumaProvider {\n const baseURL = withoutTrailingSlash(options.baseURL ?? defaultBaseURL);\n const getHeaders = () =>\n withUserAgentSuffix(\n {\n Authorization: `Bearer ${loadApiKey({\n apiKey: options.apiKey,\n environmentVariableName: 'LUMA_API_KEY',\n description: 'Luma',\n })}`,\n ...options.headers,\n },\n `ai-sdk/luma/${VERSION}`,\n );\n\n const createImageModel = (modelId: LumaImageModelId) =>\n new LumaImageModel(modelId, {\n provider: 'luma.image',\n baseURL: baseURL ?? defaultBaseURL,\n headers: getHeaders,\n fetch: options.fetch,\n });\n\n const embeddingModel = (modelId: string) => {\n throw new NoSuchModelError({\n modelId,\n modelType: 'embeddingModel',\n });\n };\n\n return {\n specificationVersion: 'v3' as const,\n image: createImageModel,\n imageModel: createImageModel,\n languageModel: (modelId: string) => {\n throw new NoSuchModelError({\n modelId,\n modelType: 'languageModel',\n });\n },\n embeddingModel,\n textEmbeddingModel: embeddingModel,\n };\n}\n\nexport const luma = createLuma();\n","import {\n ImageModelV3,\n ImageModelV3File,\n SharedV3Warning,\n InvalidResponseDataError,\n} from '@ai-sdk/provider';\nimport {\n FetchFunction,\n combineHeaders,\n createBinaryResponseHandler,\n createJsonResponseHandler,\n createJsonErrorResponseHandler,\n createStatusCodeErrorResponseHandler,\n delay,\n getFromApi,\n postJsonToApi,\n InferSchema,\n lazySchema,\n parseProviderOptions,\n zodSchema,\n} from '@ai-sdk/provider-utils';\nimport { LumaImageSettings, LumaReferenceType } from './luma-image-settings';\nimport { z } from 'zod/v4';\n\nconst DEFAULT_POLL_INTERVAL_MILLIS = 500;\nconst DEFAULT_MAX_POLL_ATTEMPTS = 60000 / DEFAULT_POLL_INTERVAL_MILLIS;\n\ninterface LumaImageModelConfig {\n provider: string;\n baseURL: string;\n headers: () => Record<string, string>;\n fetch?: FetchFunction;\n _internal?: {\n currentDate?: () => Date;\n };\n}\n\nexport class LumaImageModel implements ImageModelV3 {\n readonly specificationVersion = 'v3';\n readonly maxImagesPerCall = 1;\n readonly pollIntervalMillis = DEFAULT_POLL_INTERVAL_MILLIS;\n readonly maxPollAttempts = DEFAULT_MAX_POLL_ATTEMPTS;\n\n get provider(): string {\n return this.config.provider;\n }\n\n constructor(\n readonly modelId: string,\n private readonly config: LumaImageModelConfig,\n ) {}\n\n async doGenerate({\n prompt,\n n,\n size,\n aspectRatio,\n seed,\n providerOptions,\n headers,\n abortSignal,\n files,\n mask,\n }: Parameters<ImageModelV3['doGenerate']>[0]): Promise<\n Awaited<ReturnType<ImageModelV3['doGenerate']>>\n > {\n const warnings: Array<SharedV3Warning> = [];\n\n if (seed != null) {\n warnings.push({\n type: 'unsupported',\n feature: 'seed',\n details: 'This model does not support the `seed` option.',\n });\n }\n\n if (size != null) {\n warnings.push({\n type: 'unsupported',\n feature: 'size',\n details:\n 'This model does not support the `size` option. Use `aspectRatio` instead.',\n });\n }\n\n // Parse and validate provider options\n const lumaOptions = await parseProviderOptions({\n provider: 'luma',\n providerOptions,\n schema: lumaImageProviderOptionsSchema,\n });\n\n // Extract non-request options\n const {\n pollIntervalMillis,\n maxPollAttempts,\n referenceType,\n images: imageConfigs,\n ...providerRequestOptions\n } = lumaOptions ?? {};\n\n // Handle image editing via files with reference type support\n const editingOptions = this.getEditingOptions(\n files,\n mask,\n referenceType ?? undefined,\n imageConfigs ?? [],\n );\n\n const currentDate = this.config._internal?.currentDate?.() ?? new Date();\n const fullHeaders = combineHeaders(this.config.headers(), headers);\n const { value: generationResponse, responseHeaders } = await postJsonToApi({\n url: this.getLumaGenerationsUrl(),\n headers: fullHeaders,\n body: {\n prompt,\n ...(aspectRatio ? { aspect_ratio: aspectRatio } : {}),\n model: this.modelId,\n ...editingOptions,\n ...providerRequestOptions,\n },\n abortSignal,\n fetch: this.config.fetch,\n failedResponseHandler: this.createLumaErrorHandler(),\n successfulResponseHandler: createJsonResponseHandler(\n lumaGenerationResponseSchema,\n ),\n });\n\n const imageUrl = await this.pollForImageUrl(\n generationResponse.id,\n fullHeaders,\n abortSignal,\n {\n pollIntervalMillis: pollIntervalMillis ?? undefined,\n maxPollAttempts: maxPollAttempts ?? undefined,\n },\n );\n\n const downloadedImage = await this.downloadImage(imageUrl, abortSignal);\n\n return {\n images: [downloadedImage],\n warnings,\n response: {\n modelId: this.modelId,\n timestamp: currentDate,\n headers: responseHeaders,\n },\n };\n }\n\n private async pollForImageUrl(\n generationId: string,\n headers: Record<string, string | undefined>,\n abortSignal: AbortSignal | undefined,\n pollSettings?: { pollIntervalMillis?: number; maxPollAttempts?: number },\n ): Promise<string> {\n const url = this.getLumaGenerationsUrl(generationId);\n const maxPollAttempts =\n pollSettings?.maxPollAttempts ?? this.maxPollAttempts;\n const pollIntervalMillis =\n pollSettings?.pollIntervalMillis ?? this.pollIntervalMillis;\n\n for (let i = 0; i < maxPollAttempts; i++) {\n const { value: statusResponse } = await getFromApi({\n url,\n headers,\n abortSignal,\n fetch: this.config.fetch,\n failedResponseHandler: this.createLumaErrorHandler(),\n successfulResponseHandler: createJsonResponseHandler(\n lumaGenerationResponseSchema,\n ),\n });\n\n switch (statusResponse.state) {\n case 'completed':\n if (!statusResponse.assets?.image) {\n throw new InvalidResponseDataError({\n data: statusResponse,\n message: `Image generation completed but no image was found.`,\n });\n }\n return statusResponse.assets.image;\n case 'failed':\n throw new InvalidResponseDataError({\n data: statusResponse,\n message: `Image generation failed.`,\n });\n }\n await delay(pollIntervalMillis);\n }\n\n throw new Error(\n `Image generation timed out after ${this.maxPollAttempts} attempts.`,\n );\n }\n\n private createLumaErrorHandler() {\n return createJsonErrorResponseHandler({\n errorSchema: lumaErrorSchema,\n errorToMessage: (error: LumaErrorData) =>\n error.detail[0].msg ?? 'Unknown error',\n });\n }\n\n private getEditingOptions(\n files: ImageModelV3File[] | undefined,\n mask: ImageModelV3File | undefined,\n referenceType: LumaReferenceType = 'image',\n imageConfigs: Array<{ weight?: number | null; id?: string | null }> = [],\n ): Record<string, unknown> {\n const options: Record<string, unknown> = {};\n\n // Luma does not support mask-based inpainting\n if (mask != null) {\n throw new Error(\n 'Luma AI does not support mask-based image editing. ' +\n 'Use the prompt to describe the changes you want to make, along with ' +\n '`prompt.images` containing the source image URL.',\n );\n }\n\n if (files == null || files.length === 0) {\n return options;\n }\n\n // Validate all files are URL-based\n for (const file of files) {\n if (file.type !== 'url') {\n throw new Error(\n 'Luma AI only supports URL-based images. ' +\n 'Please provide image URLs using `prompt.images` with publicly accessible URLs. ' +\n 'Base64 and Uint8Array data are not supported.',\n );\n }\n }\n\n // Default weights per reference type\n const defaultWeights: Record<LumaReferenceType, number> = {\n image: 0.85,\n style: 0.8,\n character: 1.0, // Not used, but defined for completeness\n modify_image: 1.0,\n };\n\n switch (referenceType) {\n case 'image': {\n // Supports up to 4 images\n if (files.length > 4) {\n throw new Error(\n 'Luma AI image supports up to 4 reference images. ' +\n `You provided ${files.length} images.`,\n );\n }\n options.image = files.map((file, index) => ({\n url: (file as { type: 'url'; url: string }).url,\n weight: imageConfigs[index]?.weight ?? defaultWeights.image,\n }));\n break;\n }\n\n case 'style': {\n // Style ref accepts an array but typically uses one style image\n options.style = files.map((file, index) => ({\n url: (file as { type: 'url'; url: string }).url,\n weight: imageConfigs[index]?.weight ?? defaultWeights.style,\n }));\n break;\n }\n\n case 'character': {\n // Group images by identity id\n const identities: Record<string, string[]> = {};\n for (let i = 0; i < files.length; i++) {\n const file = files[i] as { type: 'url'; url: string };\n const identityId = imageConfigs[i]?.id ?? 'identity0';\n if (!identities[identityId]) {\n identities[identityId] = [];\n }\n identities[identityId].push(file.url);\n }\n\n // Validate each identity has at most 4 images\n for (const [identityId, images] of Object.entries(identities)) {\n if (images.length > 4) {\n throw new Error(\n `Luma AI character supports up to 4 images per identity. ` +\n `Identity '${identityId}' has ${images.length} images.`,\n );\n }\n }\n\n options.character = Object.fromEntries(\n Object.entries(identities).map(([id, images]) => [id, { images }]),\n );\n break;\n }\n\n case 'modify_image': {\n // Only supports a single image\n if (files.length > 1) {\n throw new Error(\n 'Luma AI modify_image only supports a single input image. ' +\n `You provided ${files.length} images.`,\n );\n }\n options.modify_image = {\n url: (files[0] as { type: 'url'; url: string }).url,\n weight: imageConfigs[0]?.weight ?? defaultWeights.modify_image,\n };\n break;\n }\n }\n\n return options;\n }\n\n private getLumaGenerationsUrl(generationId?: string) {\n return `${this.config.baseURL}/dream-machine/v1/generations/${\n generationId ?? 'image'\n }`;\n }\n\n private async downloadImage(\n url: string,\n abortSignal: AbortSignal | undefined,\n ): Promise<Uint8Array> {\n const { value: response } = await getFromApi({\n url,\n // No specific headers should be needed for this request as it's a\n // generated image provided by Luma.\n abortSignal,\n failedResponseHandler: createStatusCodeErrorResponseHandler(),\n successfulResponseHandler: createBinaryResponseHandler(),\n fetch: this.config.fetch,\n });\n return response;\n }\n}\n\n// limited version of the schema, focussed on what is needed for the implementation\n// this approach limits breakages when the API changes and increases efficiency\nconst lumaGenerationResponseSchema = lazySchema(() =>\n zodSchema(\n z.object({\n id: z.string(),\n state: z.enum(['queued', 'dreaming', 'completed', 'failed']),\n failure_reason: z.string().nullish(),\n assets: z\n .object({\n image: z.string(), // URL of the generated image\n })\n .nullish(),\n }),\n ),\n);\n\nconst lumaErrorSchema = z.object({\n detail: z.array(\n z.object({\n type: z.string(),\n loc: z.array(z.string()),\n msg: z.string(),\n input: z.string(),\n ctx: z\n .object({\n expected: z.string(),\n })\n .nullish(),\n }),\n ),\n});\n\nexport type LumaErrorData = z.infer<typeof lumaErrorSchema>;\n\n/**\n * Provider options schema for Luma image generation.\n *\n * @see https://docs.lumalabs.ai/docs/image-generation\n */\nexport const lumaImageProviderOptionsSchema = lazySchema(() =>\n zodSchema(\n z\n .object({\n /**\n * The type of image reference to use when providing input images.\n * - `image`: Guide generation using reference images (up to 4). Default.\n * - `style`: Apply a specific style from reference image(s).\n * - `character`: Create consistent characters from reference images (up to 4).\n * - `modify_image`: Transform a single input image with prompt guidance.\n */\n referenceType: z\n .enum(['image', 'style', 'character', 'modify_image'])\n .nullish(),\n\n /**\n * Per-image configuration array. Each entry corresponds to an image in `prompt.images`.\n * Allows setting individual weights for each reference image.\n */\n images: z\n .array(\n z.object({\n /**\n * The weight of this image's influence on the generation.\n * - For `image`: Higher weight = closer to reference (default: 0.85)\n * - For `style`: Higher weight = stronger style influence (default: 0.8)\n * - For `modify_image`: Higher weight = closer to input, lower = more creative (default: 1.0)\n */\n weight: z.number().min(0).max(1).nullish(),\n\n /**\n * The identity name for character references.\n * Used with `character` to specify which identity group the image belongs to.\n * Luma supports multiple identities (e.g., 'identity0', 'identity1') for generating\n * images with multiple consistent characters.\n * Default: 'identity0'\n */\n id: z.string().nullish(),\n }),\n )\n .nullish(),\n\n /**\n * Override the polling interval in milliseconds (default 500).\n */\n pollIntervalMillis: z.number().nullish(),\n\n /**\n * Override the maximum number of polling attempts (default 120).\n */\n maxPollAttempts: z.number().nullish(),\n })\n .passthrough(),\n ),\n);\n\nexport type LumaImageProviderOptions = InferSchema<\n typeof lumaImageProviderOptionsSchema\n>;\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n"],"mappings":";AAAA,SAAuB,wBAAoC;AAC3D;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,O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ACxB,IAAI,eAAe,SAAS;AAAA,IAC1B,UAAU;AAAA,IACV,SAAS,4BAAW;AAAA,IACpB,SAAS;AAAA,IACT,OAAO,QAAQ;AAAA,EACjB,CAAC;AAEH,QAAM,iBAAiB,CAAC,YAAoB;AAC1C,UAAM,IAAI,iBAAiB;AAAA,MACzB;AAAA,MACA,WAAW;AAAA,IACb,CAAC;AAAA,EACH;AAEA,SAAO;AAAA,IACL,sBAAsB;AAAA,IACtB,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,eAAe,CAAC,YAAoB;AAClC,YAAM,IAAI,iBAAiB;AAAA,QACzB;AAAA,QACA,WAAW;AAAA,MACb,CAAC;AAAA,IACH;AAAA,IACA;AAAA,IACA,oBAAoB;AAAA,EACtB;AACF;AAEO,IAAM,OAAO,WAAW;","names":["_a","_b"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/luma",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.55",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@ai-sdk/provider": "3.0.0-beta.
|
|
24
|
-
"@ai-sdk/provider-utils": "4.0.0-beta.
|
|
23
|
+
"@ai-sdk/provider": "3.0.0-beta.28",
|
|
24
|
+
"@ai-sdk/provider-utils": "4.0.0-beta.55"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/node": "20.17.24",
|