@decartai/sdk 0.0.17 → 0.0.19
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/realtime/client.d.ts +4 -7
- package/dist/realtime/client.js +0 -2
- package/dist/realtime/methods.js +27 -18
- package/dist/realtime/webrtc-connection.js +5 -0
- package/dist/realtime/webrtc-manager.js +3 -0
- package/dist/shared/model.d.ts +3 -10
- package/dist/shared/model.js +0 -16
- package/dist/shared/types.d.ts +0 -1
- package/dist/shared/types.js +4 -7
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -8,13 +8,12 @@ declare const realTimeClientInitialStateSchema: z.ZodObject<{
|
|
|
8
8
|
text: z.ZodString;
|
|
9
9
|
enhance: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
10
10
|
}, z.core.$strip>>;
|
|
11
|
-
mirror: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
12
11
|
}, z.core.$strip>;
|
|
13
12
|
type OnRemoteStreamFn = (stream: MediaStream) => void;
|
|
14
13
|
type RealTimeClientInitialState = z.infer<typeof realTimeClientInitialStateSchema>;
|
|
15
14
|
declare const realTimeClientConnectOptionsSchema: z.ZodObject<{
|
|
16
15
|
model: z.ZodObject<{
|
|
17
|
-
name: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodLiteral<"mirage">, z.ZodLiteral<"mirage_v2">, z.ZodLiteral<"lucy_v2v_720p_rt">]>, z.ZodUnion<readonly [z.ZodLiteral<"lucy-dev-i2v">, z.ZodLiteral<"lucy-
|
|
16
|
+
name: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodLiteral<"mirage">, z.ZodLiteral<"mirage_v2">, z.ZodLiteral<"lucy_v2v_720p_rt">]>, z.ZodUnion<readonly [z.ZodLiteral<"lucy-dev-i2v">, z.ZodLiteral<"lucy-fast-v2v">, z.ZodLiteral<"lucy-pro-t2v">, z.ZodLiteral<"lucy-pro-i2v">, z.ZodLiteral<"lucy-pro-v2v">, z.ZodLiteral<"lucy-pro-flf2v">, z.ZodLiteral<"lucy-motion">]>, z.ZodUnion<readonly [z.ZodLiteral<"lucy-pro-t2i">, z.ZodLiteral<"lucy-pro-i2i">]>]>;
|
|
18
17
|
urlPath: z.ZodString;
|
|
19
18
|
fps: z.ZodNumber;
|
|
20
19
|
width: z.ZodNumber;
|
|
@@ -27,7 +26,6 @@ declare const realTimeClientConnectOptionsSchema: z.ZodObject<{
|
|
|
27
26
|
text: z.ZodString;
|
|
28
27
|
enhance: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
29
28
|
}, z.core.$strip>>;
|
|
30
|
-
mirror: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
31
29
|
}, z.core.$strip>>;
|
|
32
30
|
customizeOffer: z.ZodOptional<z.ZodCustom<z.core.$InferInnerFunctionTypeAsync<z.core.$ZodFunctionArgs, z.core.$ZodFunctionOut>, z.core.$InferInnerFunctionTypeAsync<z.core.$ZodFunctionArgs, z.core.$ZodFunctionOut>>>;
|
|
33
31
|
}, z.core.$strip>;
|
|
@@ -41,13 +39,12 @@ type RealTimeClient = {
|
|
|
41
39
|
enhance
|
|
42
40
|
}?: {
|
|
43
41
|
enhance?: boolean;
|
|
44
|
-
}) => void
|
|
45
|
-
setMirror: (enabled: boolean) => void;
|
|
42
|
+
}) => Promise<void>;
|
|
46
43
|
isConnected: () => boolean;
|
|
47
44
|
getConnectionState: () => "connected" | "connecting" | "disconnected";
|
|
48
45
|
disconnect: () => void;
|
|
49
|
-
on: (event:
|
|
50
|
-
off: (event:
|
|
46
|
+
on: <K extends keyof Events>(event: K, listener: (data: Events[K]) => void) => void;
|
|
47
|
+
off: <K extends keyof Events>(event: K, listener: (data: Events[K]) => void) => void;
|
|
51
48
|
sessionId: string;
|
|
52
49
|
};
|
|
53
50
|
//#endregion
|
package/dist/realtime/client.js
CHANGED
|
@@ -51,11 +51,9 @@ const createRealTimeClient = (opts) => {
|
|
|
51
51
|
const { text, enhance } = options.initialState.prompt;
|
|
52
52
|
methods.setPrompt(text, { enhance });
|
|
53
53
|
}
|
|
54
|
-
if (options.initialState.mirror) methods.setMirror(options.initialState.mirror);
|
|
55
54
|
}
|
|
56
55
|
return {
|
|
57
56
|
setPrompt: methods.setPrompt,
|
|
58
|
-
setMirror: methods.setMirror,
|
|
59
57
|
isConnected: () => webrtcManager.isConnected(),
|
|
60
58
|
getConnectionState: () => webrtcManager.getConnectionState(),
|
|
61
59
|
disconnect: () => webrtcManager.cleanup(),
|
package/dist/realtime/methods.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
|
|
3
3
|
//#region src/realtime/methods.ts
|
|
4
|
+
const PROMPT_TIMEOUT_MS = 15 * 1e3;
|
|
4
5
|
const realtimeMethods = (webrtcManager) => {
|
|
5
|
-
const setPrompt = (prompt, { enhance } = {}) => {
|
|
6
|
+
const setPrompt = async (prompt, { enhance } = {}) => {
|
|
6
7
|
const parsedInput = z.object({
|
|
7
8
|
prompt: z.string().min(1),
|
|
8
9
|
enhance: z.boolean().optional().default(true)
|
|
@@ -11,24 +12,32 @@ const realtimeMethods = (webrtcManager) => {
|
|
|
11
12
|
enhance
|
|
12
13
|
});
|
|
13
14
|
if (!parsedInput.success) throw parsedInput.error;
|
|
14
|
-
webrtcManager.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
15
|
+
const emitter = webrtcManager.getWebsocketMessageEmitter();
|
|
16
|
+
let promptAckListener;
|
|
17
|
+
let timeoutId;
|
|
18
|
+
try {
|
|
19
|
+
const ackPromise = new Promise((resolve, reject) => {
|
|
20
|
+
promptAckListener = (promptAckMessage) => {
|
|
21
|
+
if (promptAckMessage.prompt === parsedInput.data.prompt) if (promptAckMessage.success) resolve();
|
|
22
|
+
else reject(promptAckMessage.error);
|
|
23
|
+
};
|
|
24
|
+
emitter.on("promptAck", promptAckListener);
|
|
25
|
+
});
|
|
26
|
+
webrtcManager.sendMessage({
|
|
27
|
+
type: "prompt",
|
|
28
|
+
prompt: parsedInput.data.prompt,
|
|
29
|
+
enhance_prompt: parsedInput.data.enhance
|
|
30
|
+
});
|
|
31
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
32
|
+
timeoutId = setTimeout(() => reject(/* @__PURE__ */ new Error("Prompt timed out")), PROMPT_TIMEOUT_MS);
|
|
33
|
+
});
|
|
34
|
+
await Promise.race([ackPromise, timeoutPromise]);
|
|
35
|
+
} finally {
|
|
36
|
+
if (promptAckListener) emitter.off("promptAck", promptAckListener);
|
|
37
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
38
|
+
}
|
|
31
39
|
};
|
|
40
|
+
return { setPrompt };
|
|
32
41
|
};
|
|
33
42
|
|
|
34
43
|
//#endregion
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { buildUserAgent } from "../utils/user-agent.js";
|
|
2
|
+
import mitt from "mitt";
|
|
2
3
|
|
|
3
4
|
//#region src/realtime/webrtc-connection.ts
|
|
4
5
|
const ICE_SERVERS = [{ urls: "stun:stun.l.google.com:19302" }];
|
|
@@ -8,6 +9,7 @@ var WebRTCConnection = class {
|
|
|
8
9
|
localStream = null;
|
|
9
10
|
connectionReject = null;
|
|
10
11
|
state = "disconnected";
|
|
12
|
+
websocketMessagesEmitter = mitt();
|
|
11
13
|
constructor(callbacks = {}) {
|
|
12
14
|
this.callbacks = callbacks;
|
|
13
15
|
}
|
|
@@ -105,6 +107,9 @@ var WebRTCConnection = class {
|
|
|
105
107
|
if (turnConfig) await this.setupNewPeerConnection(turnConfig);
|
|
106
108
|
break;
|
|
107
109
|
}
|
|
110
|
+
case "prompt_ack":
|
|
111
|
+
this.websocketMessagesEmitter.emit("promptAck", msg);
|
|
112
|
+
break;
|
|
108
113
|
}
|
|
109
114
|
} catch (error) {
|
|
110
115
|
console.error("[WebRTC] Error:", error);
|
package/dist/shared/model.d.ts
CHANGED
|
@@ -2,9 +2,9 @@ import { z } from "zod";
|
|
|
2
2
|
|
|
3
3
|
//#region src/shared/model.d.ts
|
|
4
4
|
declare const realtimeModels: z.ZodUnion<readonly [z.ZodLiteral<"mirage">, z.ZodLiteral<"mirage_v2">, z.ZodLiteral<"lucy_v2v_720p_rt">]>;
|
|
5
|
-
declare const videoModels: z.ZodUnion<readonly [z.ZodLiteral<"lucy-dev-i2v">, z.ZodLiteral<"lucy-
|
|
5
|
+
declare const videoModels: z.ZodUnion<readonly [z.ZodLiteral<"lucy-dev-i2v">, z.ZodLiteral<"lucy-fast-v2v">, z.ZodLiteral<"lucy-pro-t2v">, z.ZodLiteral<"lucy-pro-i2v">, z.ZodLiteral<"lucy-pro-v2v">, z.ZodLiteral<"lucy-pro-flf2v">, z.ZodLiteral<"lucy-motion">]>;
|
|
6
6
|
declare const imageModels: z.ZodUnion<readonly [z.ZodLiteral<"lucy-pro-t2i">, z.ZodLiteral<"lucy-pro-i2i">]>;
|
|
7
|
-
declare const modelSchema: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodLiteral<"mirage">, z.ZodLiteral<"mirage_v2">, z.ZodLiteral<"lucy_v2v_720p_rt">]>, z.ZodUnion<readonly [z.ZodLiteral<"lucy-dev-i2v">, z.ZodLiteral<"lucy-
|
|
7
|
+
declare const modelSchema: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodLiteral<"mirage">, z.ZodLiteral<"mirage_v2">, z.ZodLiteral<"lucy_v2v_720p_rt">]>, z.ZodUnion<readonly [z.ZodLiteral<"lucy-dev-i2v">, z.ZodLiteral<"lucy-fast-v2v">, z.ZodLiteral<"lucy-pro-t2v">, z.ZodLiteral<"lucy-pro-i2v">, z.ZodLiteral<"lucy-pro-v2v">, z.ZodLiteral<"lucy-pro-flf2v">, z.ZodLiteral<"lucy-motion">]>, z.ZodUnion<readonly [z.ZodLiteral<"lucy-pro-t2i">, z.ZodLiteral<"lucy-pro-i2i">]>]>;
|
|
8
8
|
type Model = z.infer<typeof modelSchema>;
|
|
9
9
|
type RealTimeModels = z.infer<typeof realtimeModels>;
|
|
10
10
|
type VideoModels = z.infer<typeof videoModels>;
|
|
@@ -51,13 +51,6 @@ declare const modelInputSchemas: {
|
|
|
51
51
|
enhance_prompt: z.ZodOptional<z.ZodBoolean>;
|
|
52
52
|
num_inference_steps: z.ZodOptional<z.ZodNumber>;
|
|
53
53
|
}, z.core.$strip>;
|
|
54
|
-
readonly "lucy-dev-v2v": z.ZodObject<{
|
|
55
|
-
prompt: z.ZodString;
|
|
56
|
-
data: z.ZodUnion<readonly [z.ZodCustom<File, File>, z.ZodCustom<Blob, Blob>, z.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>, z.ZodCustom<URL, URL>, z.ZodURL]>;
|
|
57
|
-
seed: z.ZodOptional<z.ZodNumber>;
|
|
58
|
-
resolution: z.ZodOptional<z.ZodDefault<z.ZodLiteral<"720p">>>;
|
|
59
|
-
enhance_prompt: z.ZodOptional<z.ZodBoolean>;
|
|
60
|
-
}, z.core.$strip>;
|
|
61
54
|
readonly "lucy-fast-v2v": z.ZodObject<{
|
|
62
55
|
prompt: z.ZodString;
|
|
63
56
|
data: z.ZodUnion<readonly [z.ZodCustom<File, File>, z.ZodCustom<Blob, Blob>, z.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>, z.ZodCustom<URL, URL>, z.ZodURL]>;
|
|
@@ -116,7 +109,7 @@ declare const models: {
|
|
|
116
109
|
* - `"lucy-pro-v2v"` - Video-to-video
|
|
117
110
|
* - `"lucy-pro-flf2v"` - First-last-frame-to-video
|
|
118
111
|
* - `"lucy-dev-i2v"` - Image-to-video (Dev quality)
|
|
119
|
-
* - `"lucy-
|
|
112
|
+
* - `"lucy-fast-v2v"` - Video-to-video (Fast quality)
|
|
120
113
|
*/
|
|
121
114
|
video: <T extends VideoModels>(model: T) => ModelDefinition<T>;
|
|
122
115
|
/**
|
package/dist/shared/model.js
CHANGED
|
@@ -9,7 +9,6 @@ const realtimeModels = z.union([
|
|
|
9
9
|
]);
|
|
10
10
|
const videoModels = z.union([
|
|
11
11
|
z.literal("lucy-dev-i2v"),
|
|
12
|
-
z.literal("lucy-dev-v2v"),
|
|
13
12
|
z.literal("lucy-fast-v2v"),
|
|
14
13
|
z.literal("lucy-pro-t2v"),
|
|
15
14
|
z.literal("lucy-pro-i2v"),
|
|
@@ -82,13 +81,6 @@ const modelInputSchemas = {
|
|
|
82
81
|
enhance_prompt: z.boolean().optional().describe("Whether to enhance the prompt"),
|
|
83
82
|
num_inference_steps: z.number().optional().describe("The number of inference steps")
|
|
84
83
|
}),
|
|
85
|
-
"lucy-dev-v2v": z.object({
|
|
86
|
-
prompt: z.string().min(1).max(1e3).describe("The prompt to use for the generation"),
|
|
87
|
-
data: fileInputSchema.describe("The video data to use for generation (File, Blob, ReadableStream, URL, or string URL)"),
|
|
88
|
-
seed: z.number().optional().describe("The seed to use for the generation"),
|
|
89
|
-
resolution: devResolutionSchema,
|
|
90
|
-
enhance_prompt: z.boolean().optional().describe("Whether to enhance the prompt")
|
|
91
|
-
}),
|
|
92
84
|
"lucy-fast-v2v": z.object({
|
|
93
85
|
prompt: z.string().min(1).max(1e3).describe("The prompt to use for the generation"),
|
|
94
86
|
data: fileInputSchema.describe("The video data to use for generation (File, Blob, ReadableStream, URL, or string URL)"),
|
|
@@ -183,14 +175,6 @@ const _models = {
|
|
|
183
175
|
height: 704,
|
|
184
176
|
inputSchema: modelInputSchemas["lucy-dev-i2v"]
|
|
185
177
|
},
|
|
186
|
-
"lucy-dev-v2v": {
|
|
187
|
-
urlPath: "/v1/generate/lucy-dev-v2v",
|
|
188
|
-
name: "lucy-dev-v2v",
|
|
189
|
-
fps: 25,
|
|
190
|
-
width: 1280,
|
|
191
|
-
height: 704,
|
|
192
|
-
inputSchema: modelInputSchemas["lucy-dev-v2v"]
|
|
193
|
-
},
|
|
194
178
|
"lucy-fast-v2v": {
|
|
195
179
|
urlPath: "/v1/generate/lucy-fast-v2v",
|
|
196
180
|
name: "lucy-fast-v2v",
|
package/dist/shared/types.d.ts
CHANGED
|
@@ -6,7 +6,6 @@ declare const modelStateSchema: z.ZodObject<{
|
|
|
6
6
|
text: z.ZodString;
|
|
7
7
|
enhance: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
8
8
|
}, z.core.$strip>>;
|
|
9
|
-
mirror: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
10
9
|
}, z.core.$strip>;
|
|
11
10
|
type ModelState = z.infer<typeof modelStateSchema>;
|
|
12
11
|
//#endregion
|
package/dist/shared/types.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
|
|
3
3
|
//#region src/shared/types.ts
|
|
4
|
-
const modelStateSchema = z.object({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}).optional(),
|
|
9
|
-
mirror: z.boolean().optional().default(false)
|
|
10
|
-
});
|
|
4
|
+
const modelStateSchema = z.object({ prompt: z.object({
|
|
5
|
+
text: z.string().min(1),
|
|
6
|
+
enhance: z.boolean().optional().default(true)
|
|
7
|
+
}).optional() });
|
|
11
8
|
|
|
12
9
|
//#endregion
|
|
13
10
|
export { modelStateSchema };
|
package/dist/version.js
CHANGED