@decartai/sdk 0.0.33 → 0.0.35
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/dist/index.d.ts +19 -11
- package/dist/index.js +29 -15
- package/dist/process/request.js +5 -1
- package/dist/process/types.d.ts +34 -3
- package/dist/queue/request.js +15 -3
- package/dist/shared/model.d.ts +55 -10
- package/dist/shared/model.js +7 -1
- package/dist/shared/request.js +15 -5
- package/dist/tokens/client.js +5 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ImageModelDefinition, ImageModels, Model, ModelDefinition, RealTimeModels, VideoModelDefinition, VideoModels, isImageModel, isRealtimeModel, isVideoModel, models } from "./shared/model.js";
|
|
2
|
-
import { FileInput, ProcessOptions } from "./process/types.js";
|
|
2
|
+
import { FileInput, ProcessOptions, ReactNativeFile } from "./process/types.js";
|
|
3
3
|
import { ProcessClient } from "./process/client.js";
|
|
4
4
|
import { JobStatus, JobStatusResponse, JobSubmitResponse, QueueJobResult, QueueSubmitAndPollOptions, QueueSubmitOptions } from "./queue/types.js";
|
|
5
5
|
import { QueueClient } from "./queue/client.js";
|
|
@@ -7,30 +7,38 @@ import { DecartSDKError, ERROR_CODES } from "./utils/errors.js";
|
|
|
7
7
|
import { AvatarOptions, RealTimeClient, RealTimeClientConnectOptions, RealTimeClientInitialState } from "./realtime/client.js";
|
|
8
8
|
import { ModelState } from "./shared/types.js";
|
|
9
9
|
import { CreateTokenResponse, TokensClient } from "./tokens/client.js";
|
|
10
|
-
import { z } from "zod";
|
|
11
10
|
|
|
12
11
|
//#region src/index.d.ts
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
type DecartClientOptions = {
|
|
13
|
+
proxy: string;
|
|
14
|
+
apiKey?: never;
|
|
15
|
+
baseUrl?: string;
|
|
16
|
+
integration?: string;
|
|
17
|
+
} | {
|
|
18
|
+
proxy?: never;
|
|
19
|
+
apiKey?: string;
|
|
20
|
+
baseUrl?: string;
|
|
21
|
+
integration?: string;
|
|
22
|
+
};
|
|
19
23
|
/**
|
|
20
24
|
* Create a Decart API client.
|
|
21
25
|
*
|
|
22
26
|
* @param options - Configuration options
|
|
23
|
-
* @param options.
|
|
27
|
+
* @param options.proxy - URL of the proxy server. When set, the client will use the proxy instead of direct API access and apiKey is not required.
|
|
28
|
+
* @param options.apiKey - API key for authentication.
|
|
24
29
|
* @param options.baseUrl - Override the default API base URL.
|
|
25
30
|
* @param options.integration - Optional integration identifier.
|
|
26
31
|
*
|
|
27
32
|
* @example
|
|
28
33
|
* ```ts
|
|
29
|
-
* // Option 1: Explicit API key
|
|
34
|
+
* // (direct API access)Option 1: Explicit API key
|
|
30
35
|
* const client = createDecartClient({ apiKey: "your-api-key" });
|
|
31
36
|
*
|
|
32
37
|
* // Option 2: Using DECART_API_KEY environment variable
|
|
33
38
|
* const client = createDecartClient();
|
|
39
|
+
*
|
|
40
|
+
* // Option 3: Using proxy (client-side, no API key needed)
|
|
41
|
+
* const client = createDecartClient({ proxy: "https://your-server.com/api/decart" });
|
|
34
42
|
* ```
|
|
35
43
|
*/
|
|
36
44
|
declare const createDecartClient: (options?: DecartClientOptions) => {
|
|
@@ -109,4 +117,4 @@ declare const createDecartClient: (options?: DecartClientOptions) => {
|
|
|
109
117
|
tokens: TokensClient;
|
|
110
118
|
};
|
|
111
119
|
//#endregion
|
|
112
|
-
export { type AvatarOptions, type CreateTokenResponse, DecartClientOptions, type DecartSDKError, ERROR_CODES, type FileInput, type ImageModelDefinition, type ImageModels, type JobStatus, type JobStatusResponse, type JobSubmitResponse, type Model, type ModelDefinition, type ModelState, type ProcessClient, type ProcessOptions, type QueueClient, type QueueJobResult, type QueueSubmitAndPollOptions, type QueueSubmitOptions, type RealTimeClient, type RealTimeClientConnectOptions, type RealTimeClientInitialState, type RealTimeModels, type TokensClient, type VideoModelDefinition, type VideoModels, createDecartClient, isImageModel, isRealtimeModel, isVideoModel, models };
|
|
120
|
+
export { type AvatarOptions, type CreateTokenResponse, DecartClientOptions, type DecartSDKError, ERROR_CODES, type FileInput, type ImageModelDefinition, type ImageModels, type JobStatus, type JobStatusResponse, type JobSubmitResponse, type Model, type ModelDefinition, type ModelState, type ProcessClient, type ProcessOptions, type QueueClient, type QueueJobResult, type QueueSubmitAndPollOptions, type QueueSubmitOptions, type ReactNativeFile, type RealTimeClient, type RealTimeClientConnectOptions, type RealTimeClientInitialState, type RealTimeModels, type TokensClient, type VideoModelDefinition, type VideoModels, createDecartClient, isImageModel, isRealtimeModel, isVideoModel, models };
|
package/dist/index.js
CHANGED
|
@@ -8,59 +8,73 @@ import { readEnv } from "./utils/env.js";
|
|
|
8
8
|
import { z } from "zod";
|
|
9
9
|
|
|
10
10
|
//#region src/index.ts
|
|
11
|
+
const proxySchema = z.union([z.string().url(), z.string().startsWith("/")]);
|
|
11
12
|
const decartClientOptionsSchema = z.object({
|
|
12
13
|
apiKey: z.string().min(1).optional(),
|
|
13
14
|
baseUrl: z.url().optional(),
|
|
15
|
+
proxy: proxySchema.optional(),
|
|
14
16
|
integration: z.string().optional()
|
|
15
|
-
})
|
|
17
|
+
}).refine((data) => {
|
|
18
|
+
const hasProxy = !!data.proxy;
|
|
19
|
+
const hasApiKey = !!data.apiKey;
|
|
20
|
+
return !(hasProxy && hasApiKey);
|
|
21
|
+
}, { message: "Cannot provide both 'proxy' and 'apiKey'. Use 'proxy' for proxy mode or 'apiKey' for direct API access." });
|
|
16
22
|
/**
|
|
17
23
|
* Create a Decart API client.
|
|
18
24
|
*
|
|
19
25
|
* @param options - Configuration options
|
|
20
|
-
* @param options.
|
|
26
|
+
* @param options.proxy - URL of the proxy server. When set, the client will use the proxy instead of direct API access and apiKey is not required.
|
|
27
|
+
* @param options.apiKey - API key for authentication.
|
|
21
28
|
* @param options.baseUrl - Override the default API base URL.
|
|
22
29
|
* @param options.integration - Optional integration identifier.
|
|
23
30
|
*
|
|
24
31
|
* @example
|
|
25
32
|
* ```ts
|
|
26
|
-
* // Option 1: Explicit API key
|
|
33
|
+
* // (direct API access)Option 1: Explicit API key
|
|
27
34
|
* const client = createDecartClient({ apiKey: "your-api-key" });
|
|
28
35
|
*
|
|
29
36
|
* // Option 2: Using DECART_API_KEY environment variable
|
|
30
37
|
* const client = createDecartClient();
|
|
38
|
+
*
|
|
39
|
+
* // Option 3: Using proxy (client-side, no API key needed)
|
|
40
|
+
* const client = createDecartClient({ proxy: "https://your-server.com/api/decart" });
|
|
31
41
|
* ```
|
|
32
42
|
*/
|
|
33
43
|
const createDecartClient = (options = {}) => {
|
|
34
|
-
const
|
|
35
|
-
if (!apiKey) throw createInvalidApiKeyError();
|
|
36
|
-
const parsedOptions = decartClientOptionsSchema.safeParse({
|
|
37
|
-
...options,
|
|
38
|
-
apiKey
|
|
39
|
-
});
|
|
44
|
+
const parsedOptions = decartClientOptionsSchema.safeParse(options);
|
|
40
45
|
if (!parsedOptions.success) {
|
|
41
|
-
|
|
46
|
+
const issue = parsedOptions.error.issues[0];
|
|
47
|
+
if (issue.path.includes("apiKey")) throw createInvalidApiKeyError();
|
|
48
|
+
if (issue.path.includes("baseUrl")) throw createInvalidBaseUrlError(issue.path.includes("baseUrl") ? options.baseUrl : void 0);
|
|
49
|
+
if (issue.path.includes("proxy")) throw createInvalidBaseUrlError(issue.path.includes("proxy") ? options.proxy : void 0);
|
|
42
50
|
throw parsedOptions.error;
|
|
43
51
|
}
|
|
44
|
-
const
|
|
52
|
+
const isProxyMode = "proxy" in parsedOptions.data && !!parsedOptions.data.proxy;
|
|
53
|
+
const apiKey = isProxyMode ? void 0 : ("apiKey" in parsedOptions.data ? parsedOptions.data.apiKey : void 0) ?? readEnv("DECART_API_KEY");
|
|
54
|
+
if (!isProxyMode && !apiKey) throw createInvalidApiKeyError();
|
|
55
|
+
let baseUrl;
|
|
56
|
+
if (isProxyMode && "proxy" in parsedOptions.data && parsedOptions.data.proxy) baseUrl = parsedOptions.data.proxy;
|
|
57
|
+
else baseUrl = parsedOptions.data.baseUrl || "https://api.decart.ai";
|
|
58
|
+
const { integration } = parsedOptions.data;
|
|
45
59
|
return {
|
|
46
60
|
realtime: createRealTimeClient({
|
|
47
61
|
baseUrl: "wss://api3.decart.ai",
|
|
48
|
-
apiKey,
|
|
62
|
+
apiKey: apiKey || "",
|
|
49
63
|
integration
|
|
50
64
|
}),
|
|
51
65
|
process: createProcessClient({
|
|
52
66
|
baseUrl,
|
|
53
|
-
apiKey,
|
|
67
|
+
apiKey: apiKey || "",
|
|
54
68
|
integration
|
|
55
69
|
}),
|
|
56
70
|
queue: createQueueClient({
|
|
57
71
|
baseUrl,
|
|
58
|
-
apiKey,
|
|
72
|
+
apiKey: apiKey || "",
|
|
59
73
|
integration
|
|
60
74
|
}),
|
|
61
75
|
tokens: createTokensClient({
|
|
62
76
|
baseUrl,
|
|
63
|
-
apiKey,
|
|
77
|
+
apiKey: apiKey || "",
|
|
64
78
|
integration
|
|
65
79
|
})
|
|
66
80
|
};
|
package/dist/process/request.js
CHANGED
|
@@ -5,9 +5,13 @@ import { buildAuthHeaders, buildFormData } from "../shared/request.js";
|
|
|
5
5
|
async function sendRequest({ baseUrl, apiKey, model, inputs, signal, integration }) {
|
|
6
6
|
const formData = buildFormData(inputs);
|
|
7
7
|
const endpoint = `${baseUrl}${model.urlPath}`;
|
|
8
|
+
const headers = buildAuthHeaders({
|
|
9
|
+
apiKey,
|
|
10
|
+
integration
|
|
11
|
+
});
|
|
8
12
|
const response = await fetch(endpoint, {
|
|
9
13
|
method: "POST",
|
|
10
|
-
headers
|
|
14
|
+
headers,
|
|
11
15
|
body: formData,
|
|
12
16
|
signal
|
|
13
17
|
});
|
package/dist/process/types.d.ts
CHANGED
|
@@ -2,7 +2,17 @@ import { ImageModelDefinition, ImageModels, ModelDefinition, ModelInputSchemas,
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
|
|
4
4
|
//#region src/process/types.d.ts
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* React Native file object format for file uploads.
|
|
8
|
+
* This format is used by React Native's FormData to properly handle file uploads with MIME types.
|
|
9
|
+
*/
|
|
10
|
+
interface ReactNativeFile {
|
|
11
|
+
uri: string;
|
|
12
|
+
type: string;
|
|
13
|
+
name: string;
|
|
14
|
+
}
|
|
15
|
+
type FileInput = File | Blob | ReadableStream | URL | string | ReactNativeFile;
|
|
6
16
|
type InferModelInputs<T extends ModelDefinition> = T["name"] extends keyof ModelInputSchemas ? z.input<ModelInputSchemas[T["name"]]> : Record<string, never>;
|
|
7
17
|
/**
|
|
8
18
|
* Model-specific input documentation for image generation models.
|
|
@@ -49,6 +59,27 @@ interface VideoModelInputs {
|
|
|
49
59
|
*/
|
|
50
60
|
data?: FileInput;
|
|
51
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Model-specific input documentation for lucy-pro-v2v.
|
|
64
|
+
*/
|
|
65
|
+
interface VideoEditInputs {
|
|
66
|
+
/**
|
|
67
|
+
* Text description to use for the video editing.
|
|
68
|
+
*
|
|
69
|
+
* See our [Prompt Engineering](https://docs.platform.decart.ai/models/video/video-generation#prompt-engineering) guide for how to write prompt for Decart video models effectively.
|
|
70
|
+
*/
|
|
71
|
+
prompt: string;
|
|
72
|
+
/**
|
|
73
|
+
* Video file to process.
|
|
74
|
+
* Can be a File, Blob, ReadableStream, URL, or string URL.
|
|
75
|
+
*/
|
|
76
|
+
data: FileInput;
|
|
77
|
+
/**
|
|
78
|
+
* Optional reference image to guide what to add to the video.
|
|
79
|
+
* Can be a File, Blob, ReadableStream, URL, or string URL.
|
|
80
|
+
*/
|
|
81
|
+
reference_image?: FileInput;
|
|
82
|
+
}
|
|
52
83
|
/**
|
|
53
84
|
* Model-specific input documentation for lucy-restyle-v2v.
|
|
54
85
|
* Allows either prompt or reference_image (mutually exclusive).
|
|
@@ -85,7 +116,7 @@ interface PromptInput {
|
|
|
85
116
|
* This allows different models to have field-specific documentation while maintaining type safety.
|
|
86
117
|
* Specific models are checked first, then falls back to category-based selection.
|
|
87
118
|
*/
|
|
88
|
-
type ModelSpecificInputs<T extends ModelDefinition> = T["name"] extends "lucy-pro-i2i" ? ImageEditingInputs : T["name"] extends "lucy-restyle-v2v" ? VideoRestyleInputs : T["name"] extends ImageModels ? ImageGenerationInputs : T["name"] extends VideoModels ? VideoModelInputs : PromptInput;
|
|
119
|
+
type ModelSpecificInputs<T extends ModelDefinition> = T["name"] extends "lucy-pro-i2i" ? ImageEditingInputs : T["name"] extends "lucy-restyle-v2v" ? VideoRestyleInputs : T["name"] extends "lucy-pro-v2v" ? VideoEditInputs : T["name"] extends ImageModels ? ImageGenerationInputs : T["name"] extends VideoModels ? VideoModelInputs : PromptInput;
|
|
89
120
|
interface ProcessInputs {
|
|
90
121
|
/**
|
|
91
122
|
* Random seed for reproducible results.
|
|
@@ -172,4 +203,4 @@ type ProcessOptions<T extends ImageModelDefinition = ImageModelDefinition> = {
|
|
|
172
203
|
signal?: AbortSignal;
|
|
173
204
|
} & MergeDocumentedInputs<T>;
|
|
174
205
|
//#endregion
|
|
175
|
-
export { FileInput, InferModelInputs, ModelSpecificInputs, ProcessInputs, ProcessOptions };
|
|
206
|
+
export { FileInput, InferModelInputs, ModelSpecificInputs, ProcessInputs, ProcessOptions, ReactNativeFile };
|
package/dist/queue/request.js
CHANGED
|
@@ -10,9 +10,13 @@ async function submitJob({ baseUrl, apiKey, model, inputs, signal, integration }
|
|
|
10
10
|
const formData = buildFormData(inputs);
|
|
11
11
|
if (!model.queueUrlPath) throw createQueueSubmitError(`Model ${model.name} does not support queue processing`, 400);
|
|
12
12
|
const endpoint = `${baseUrl}${model.queueUrlPath}`;
|
|
13
|
+
const headers = buildAuthHeaders({
|
|
14
|
+
apiKey,
|
|
15
|
+
integration
|
|
16
|
+
});
|
|
13
17
|
const response = await fetch(endpoint, {
|
|
14
18
|
method: "POST",
|
|
15
|
-
headers
|
|
19
|
+
headers,
|
|
16
20
|
body: formData,
|
|
17
21
|
signal
|
|
18
22
|
});
|
|
@@ -28,9 +32,13 @@ async function submitJob({ baseUrl, apiKey, model, inputs, signal, integration }
|
|
|
28
32
|
*/
|
|
29
33
|
async function getJobStatus({ baseUrl, apiKey, jobId, signal, integration }) {
|
|
30
34
|
const endpoint = `${baseUrl}/v1/jobs/${jobId}`;
|
|
35
|
+
const headers = buildAuthHeaders({
|
|
36
|
+
apiKey,
|
|
37
|
+
integration
|
|
38
|
+
});
|
|
31
39
|
const response = await fetch(endpoint, {
|
|
32
40
|
method: "GET",
|
|
33
|
-
headers
|
|
41
|
+
headers,
|
|
34
42
|
signal
|
|
35
43
|
});
|
|
36
44
|
if (!response.ok) {
|
|
@@ -45,9 +53,13 @@ async function getJobStatus({ baseUrl, apiKey, jobId, signal, integration }) {
|
|
|
45
53
|
*/
|
|
46
54
|
async function getJobContent({ baseUrl, apiKey, jobId, signal, integration }) {
|
|
47
55
|
const endpoint = `${baseUrl}/v1/jobs/${jobId}/content`;
|
|
56
|
+
const headers = buildAuthHeaders({
|
|
57
|
+
apiKey,
|
|
58
|
+
integration
|
|
59
|
+
});
|
|
48
60
|
const response = await fetch(endpoint, {
|
|
49
61
|
method: "GET",
|
|
50
|
-
headers
|
|
62
|
+
headers,
|
|
51
63
|
signal
|
|
52
64
|
});
|
|
53
65
|
if (!response.ok) {
|
package/dist/shared/model.d.ts
CHANGED
|
@@ -33,7 +33,11 @@ declare const modelInputSchemas: {
|
|
|
33
33
|
}, z.core.$strip>;
|
|
34
34
|
readonly "lucy-pro-i2v": z.ZodObject<{
|
|
35
35
|
prompt: z.ZodString;
|
|
36
|
-
data: z.ZodUnion<readonly [z.ZodCustom<File, File>, z.ZodCustom<Blob, Blob>, z.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>, z.ZodCustom<URL, URL>, z.ZodURL
|
|
36
|
+
data: z.ZodUnion<readonly [z.ZodCustom<File, File>, z.ZodCustom<Blob, Blob>, z.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>, z.ZodCustom<URL, URL>, z.ZodURL, z.ZodObject<{
|
|
37
|
+
uri: z.ZodString;
|
|
38
|
+
type: z.ZodString;
|
|
39
|
+
name: z.ZodString;
|
|
40
|
+
}, z.core.$strip>]>;
|
|
37
41
|
seed: z.ZodOptional<z.ZodNumber>;
|
|
38
42
|
resolution: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
|
|
39
43
|
"720p": "720p";
|
|
@@ -42,13 +46,26 @@ declare const modelInputSchemas: {
|
|
|
42
46
|
}, z.core.$strip>;
|
|
43
47
|
readonly "lucy-dev-i2v": z.ZodObject<{
|
|
44
48
|
prompt: z.ZodString;
|
|
45
|
-
data: z.ZodUnion<readonly [z.ZodCustom<File, File>, z.ZodCustom<Blob, Blob>, z.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>, z.ZodCustom<URL, URL>, z.ZodURL
|
|
49
|
+
data: z.ZodUnion<readonly [z.ZodCustom<File, File>, z.ZodCustom<Blob, Blob>, z.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>, z.ZodCustom<URL, URL>, z.ZodURL, z.ZodObject<{
|
|
50
|
+
uri: z.ZodString;
|
|
51
|
+
type: z.ZodString;
|
|
52
|
+
name: z.ZodString;
|
|
53
|
+
}, z.core.$strip>]>;
|
|
46
54
|
seed: z.ZodOptional<z.ZodNumber>;
|
|
47
55
|
resolution: z.ZodOptional<z.ZodDefault<z.ZodLiteral<"720p">>>;
|
|
48
56
|
}, z.core.$strip>;
|
|
49
57
|
readonly "lucy-pro-v2v": z.ZodObject<{
|
|
50
58
|
prompt: z.ZodString;
|
|
51
|
-
data: z.ZodUnion<readonly [z.ZodCustom<File, File>, z.ZodCustom<Blob, Blob>, z.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>, z.ZodCustom<URL, URL>, z.ZodURL
|
|
59
|
+
data: z.ZodUnion<readonly [z.ZodCustom<File, File>, z.ZodCustom<Blob, Blob>, z.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>, z.ZodCustom<URL, URL>, z.ZodURL, z.ZodObject<{
|
|
60
|
+
uri: z.ZodString;
|
|
61
|
+
type: z.ZodString;
|
|
62
|
+
name: z.ZodString;
|
|
63
|
+
}, z.core.$strip>]>;
|
|
64
|
+
reference_image: z.ZodOptional<z.ZodUnion<readonly [z.ZodCustom<File, File>, z.ZodCustom<Blob, Blob>, z.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>, z.ZodCustom<URL, URL>, z.ZodURL, z.ZodObject<{
|
|
65
|
+
uri: z.ZodString;
|
|
66
|
+
type: z.ZodString;
|
|
67
|
+
name: z.ZodString;
|
|
68
|
+
}, z.core.$strip>]>>;
|
|
52
69
|
seed: z.ZodOptional<z.ZodNumber>;
|
|
53
70
|
resolution: z.ZodDefault<z.ZodOptional<z.ZodLiteral<"720p">>>;
|
|
54
71
|
enhance_prompt: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -56,15 +73,27 @@ declare const modelInputSchemas: {
|
|
|
56
73
|
}, z.core.$strip>;
|
|
57
74
|
readonly "lucy-fast-v2v": z.ZodObject<{
|
|
58
75
|
prompt: z.ZodString;
|
|
59
|
-
data: z.ZodUnion<readonly [z.ZodCustom<File, File>, z.ZodCustom<Blob, Blob>, z.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>, z.ZodCustom<URL, URL>, z.ZodURL
|
|
76
|
+
data: z.ZodUnion<readonly [z.ZodCustom<File, File>, z.ZodCustom<Blob, Blob>, z.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>, z.ZodCustom<URL, URL>, z.ZodURL, z.ZodObject<{
|
|
77
|
+
uri: z.ZodString;
|
|
78
|
+
type: z.ZodString;
|
|
79
|
+
name: z.ZodString;
|
|
80
|
+
}, z.core.$strip>]>;
|
|
60
81
|
seed: z.ZodOptional<z.ZodNumber>;
|
|
61
82
|
resolution: z.ZodDefault<z.ZodOptional<z.ZodLiteral<"720p">>>;
|
|
62
83
|
enhance_prompt: z.ZodOptional<z.ZodBoolean>;
|
|
63
84
|
}, z.core.$strip>;
|
|
64
85
|
readonly "lucy-pro-flf2v": z.ZodObject<{
|
|
65
86
|
prompt: z.ZodString;
|
|
66
|
-
start: z.ZodUnion<readonly [z.ZodCustom<File, File>, z.ZodCustom<Blob, Blob>, z.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>, z.ZodCustom<URL, URL>, z.ZodURL
|
|
67
|
-
|
|
87
|
+
start: z.ZodUnion<readonly [z.ZodCustom<File, File>, z.ZodCustom<Blob, Blob>, z.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>, z.ZodCustom<URL, URL>, z.ZodURL, z.ZodObject<{
|
|
88
|
+
uri: z.ZodString;
|
|
89
|
+
type: z.ZodString;
|
|
90
|
+
name: z.ZodString;
|
|
91
|
+
}, z.core.$strip>]>;
|
|
92
|
+
end: z.ZodUnion<readonly [z.ZodCustom<File, File>, z.ZodCustom<Blob, Blob>, z.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>, z.ZodCustom<URL, URL>, z.ZodURL, z.ZodObject<{
|
|
93
|
+
uri: z.ZodString;
|
|
94
|
+
type: z.ZodString;
|
|
95
|
+
name: z.ZodString;
|
|
96
|
+
}, z.core.$strip>]>;
|
|
68
97
|
seed: z.ZodOptional<z.ZodNumber>;
|
|
69
98
|
resolution: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
|
|
70
99
|
"720p": "720p";
|
|
@@ -73,7 +102,11 @@ declare const modelInputSchemas: {
|
|
|
73
102
|
}, z.core.$strip>;
|
|
74
103
|
readonly "lucy-pro-i2i": z.ZodObject<{
|
|
75
104
|
prompt: z.ZodString;
|
|
76
|
-
data: z.ZodUnion<readonly [z.ZodCustom<File, File>, z.ZodCustom<Blob, Blob>, z.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>, z.ZodCustom<URL, URL>, z.ZodURL
|
|
105
|
+
data: z.ZodUnion<readonly [z.ZodCustom<File, File>, z.ZodCustom<Blob, Blob>, z.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>, z.ZodCustom<URL, URL>, z.ZodURL, z.ZodObject<{
|
|
106
|
+
uri: z.ZodString;
|
|
107
|
+
type: z.ZodString;
|
|
108
|
+
name: z.ZodString;
|
|
109
|
+
}, z.core.$strip>]>;
|
|
77
110
|
seed: z.ZodOptional<z.ZodNumber>;
|
|
78
111
|
resolution: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
|
|
79
112
|
"720p": "720p";
|
|
@@ -82,7 +115,11 @@ declare const modelInputSchemas: {
|
|
|
82
115
|
enhance_prompt: z.ZodOptional<z.ZodBoolean>;
|
|
83
116
|
}, z.core.$strip>;
|
|
84
117
|
readonly "lucy-motion": z.ZodObject<{
|
|
85
|
-
data: z.ZodUnion<readonly [z.ZodCustom<File, File>, z.ZodCustom<Blob, Blob>, z.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>, z.ZodCustom<URL, URL>, z.ZodURL
|
|
118
|
+
data: z.ZodUnion<readonly [z.ZodCustom<File, File>, z.ZodCustom<Blob, Blob>, z.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>, z.ZodCustom<URL, URL>, z.ZodURL, z.ZodObject<{
|
|
119
|
+
uri: z.ZodString;
|
|
120
|
+
type: z.ZodString;
|
|
121
|
+
name: z.ZodString;
|
|
122
|
+
}, z.core.$strip>]>;
|
|
86
123
|
trajectory: z.ZodArray<z.ZodObject<{
|
|
87
124
|
frame: z.ZodNumber;
|
|
88
125
|
x: z.ZodNumber;
|
|
@@ -93,8 +130,16 @@ declare const modelInputSchemas: {
|
|
|
93
130
|
}, z.core.$strip>;
|
|
94
131
|
readonly "lucy-restyle-v2v": z.ZodObject<{
|
|
95
132
|
prompt: z.ZodOptional<z.ZodString>;
|
|
96
|
-
reference_image: z.ZodOptional<z.ZodUnion<readonly [z.ZodCustom<File, File>, z.ZodCustom<Blob, Blob>, z.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>, z.ZodCustom<URL, URL>, z.ZodURL
|
|
97
|
-
|
|
133
|
+
reference_image: z.ZodOptional<z.ZodUnion<readonly [z.ZodCustom<File, File>, z.ZodCustom<Blob, Blob>, z.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>, z.ZodCustom<URL, URL>, z.ZodURL, z.ZodObject<{
|
|
134
|
+
uri: z.ZodString;
|
|
135
|
+
type: z.ZodString;
|
|
136
|
+
name: z.ZodString;
|
|
137
|
+
}, z.core.$strip>]>>;
|
|
138
|
+
data: z.ZodUnion<readonly [z.ZodCustom<File, File>, z.ZodCustom<Blob, Blob>, z.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>, z.ZodCustom<URL, URL>, z.ZodURL, z.ZodObject<{
|
|
139
|
+
uri: z.ZodString;
|
|
140
|
+
type: z.ZodString;
|
|
141
|
+
name: z.ZodString;
|
|
142
|
+
}, z.core.$strip>]>;
|
|
98
143
|
seed: z.ZodOptional<z.ZodNumber>;
|
|
99
144
|
resolution: z.ZodDefault<z.ZodOptional<z.ZodLiteral<"720p">>>;
|
|
100
145
|
enhance_prompt: z.ZodOptional<z.ZodBoolean>;
|
package/dist/shared/model.js
CHANGED
|
@@ -38,7 +38,12 @@ const fileInputSchema = z.union([
|
|
|
38
38
|
z.instanceof(Blob),
|
|
39
39
|
z.instanceof(ReadableStream),
|
|
40
40
|
z.instanceof(URL),
|
|
41
|
-
z.url()
|
|
41
|
+
z.url(),
|
|
42
|
+
z.object({
|
|
43
|
+
uri: z.string(),
|
|
44
|
+
type: z.string(),
|
|
45
|
+
name: z.string()
|
|
46
|
+
})
|
|
42
47
|
]);
|
|
43
48
|
/**
|
|
44
49
|
* Resolution schema for dev models. Supports only 720p.
|
|
@@ -87,6 +92,7 @@ const modelInputSchemas = {
|
|
|
87
92
|
"lucy-pro-v2v": z.object({
|
|
88
93
|
prompt: z.string().min(1).max(1e3).describe("The prompt to use for the generation"),
|
|
89
94
|
data: fileInputSchema.describe("The video data to use for generation (File, Blob, ReadableStream, URL, or string URL). Output video is limited to 5 seconds."),
|
|
95
|
+
reference_image: fileInputSchema.optional().describe("Optional reference image to guide what to add to the video (File, Blob, ReadableStream, URL, or string URL)"),
|
|
90
96
|
seed: z.number().optional().describe("The seed to use for the generation"),
|
|
91
97
|
resolution: proV2vResolutionSchema,
|
|
92
98
|
enhance_prompt: z.boolean().optional().describe("Whether to enhance the prompt"),
|
package/dist/shared/request.js
CHANGED
|
@@ -3,9 +3,17 @@ import { buildUserAgent } from "../utils/user-agent.js";
|
|
|
3
3
|
|
|
4
4
|
//#region src/shared/request.ts
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Type guard to check if a value is a React Native file object.
|
|
7
|
+
*/
|
|
8
|
+
function isReactNativeFile(value) {
|
|
9
|
+
return typeof value === "object" && value !== null && typeof value.uri === "string" && typeof value.type === "string" && typeof value.name === "string";
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Convert various file input types to a Blob or React Native file object.
|
|
13
|
+
* React Native file objects are passed through as-is for proper FormData handling.
|
|
7
14
|
*/
|
|
8
15
|
async function fileInputToBlob(input) {
|
|
16
|
+
if (isReactNativeFile(input)) return input;
|
|
9
17
|
if (input instanceof Blob || input instanceof File) return input;
|
|
10
18
|
if (input instanceof ReadableStream) return new Response(input).blob();
|
|
11
19
|
if (typeof input === "string" || input instanceof URL) {
|
|
@@ -20,10 +28,11 @@ async function fileInputToBlob(input) {
|
|
|
20
28
|
/**
|
|
21
29
|
* Build common headers for API requests.
|
|
22
30
|
*/
|
|
23
|
-
function buildAuthHeaders(
|
|
31
|
+
function buildAuthHeaders(options = {}) {
|
|
32
|
+
const { apiKey, integration } = options;
|
|
24
33
|
return {
|
|
25
|
-
"
|
|
26
|
-
"
|
|
34
|
+
"User-Agent": buildUserAgent(integration),
|
|
35
|
+
...apiKey ? { "X-API-KEY": apiKey } : {}
|
|
27
36
|
};
|
|
28
37
|
}
|
|
29
38
|
/**
|
|
@@ -31,7 +40,8 @@ function buildAuthHeaders(apiKey, integration) {
|
|
|
31
40
|
*/
|
|
32
41
|
function buildFormData(inputs) {
|
|
33
42
|
const formData = new FormData();
|
|
34
|
-
for (const [key, value] of Object.entries(inputs)) if (value !== void 0 && value !== null) if (value
|
|
43
|
+
for (const [key, value] of Object.entries(inputs)) if (value !== void 0 && value !== null) if (isReactNativeFile(value)) formData.append(key, value);
|
|
44
|
+
else if (value instanceof Blob) formData.append(key, value);
|
|
35
45
|
else if (typeof value === "object" && value !== null) formData.append(key, JSON.stringify(value));
|
|
36
46
|
else formData.append(key, String(value));
|
|
37
47
|
return formData;
|
package/dist/tokens/client.js
CHANGED
|
@@ -5,9 +5,13 @@ import { buildAuthHeaders } from "../shared/request.js";
|
|
|
5
5
|
const createTokensClient = (opts) => {
|
|
6
6
|
const { baseUrl, apiKey, integration } = opts;
|
|
7
7
|
const create = async () => {
|
|
8
|
+
const headers = buildAuthHeaders({
|
|
9
|
+
apiKey,
|
|
10
|
+
integration
|
|
11
|
+
});
|
|
8
12
|
const response = await fetch(`${baseUrl}/v1/client/tokens`, {
|
|
9
13
|
method: "POST",
|
|
10
|
-
headers
|
|
14
|
+
headers
|
|
11
15
|
});
|
|
12
16
|
if (!response.ok) {
|
|
13
17
|
const errorText = await response.text().catch(() => "Unknown error");
|