@decartai/sdk 0.1.2 → 0.1.4

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.
@@ -1,7 +1,7 @@
1
1
  import { createConsoleLogger } from "../utils/logger.js";
2
2
  import { REALTIME_CONFIG } from "./config-realtime.js";
3
3
  import mitt from "mitt";
4
- import { Room, RoomEvent, Track, TrackEvent } from "livekit-client";
4
+ import { Room, RoomEvent, Track } from "livekit-client";
5
5
  //#region src/realtime/media-channel.ts
6
6
  function getDefaultVideoPublishOptions(videoCodec) {
7
7
  const resolvedCodec = videoCodec ?? REALTIME_CONFIG.livekit.defaultVideoCodec;
@@ -40,16 +40,13 @@ var MediaChannel = class {
40
40
  room.on(RoomEvent.TrackSubscribed, (track, _pub, participant) => {
41
41
  if (!participant.identity.startsWith(REALTIME_CONFIG.livekit.inferenceServerIdentityPrefix)) return;
42
42
  if (track.kind !== Track.Kind.Video && track.kind !== Track.Kind.Audio) return;
43
- track.attach();
44
43
  const mediaStreamTrack = track.mediaStreamTrack;
45
44
  if (mediaStreamTrack) {
46
- this.remoteStream ??= new MediaStream();
47
- if (!this.remoteStream.getTracks().includes(mediaStreamTrack)) this.remoteStream.addTrack(mediaStreamTrack);
45
+ const tracks = this.remoteStream?.getTracks() ?? [];
46
+ if (!tracks.includes(mediaStreamTrack)) tracks.push(mediaStreamTrack);
47
+ this.remoteStream = new MediaStream(tracks);
48
48
  this.events.emit("remoteStream", this.remoteStream);
49
49
  }
50
- track.on(TrackEvent.VideoPlaybackStarted, () => {
51
- this.events.emit("firstFrame");
52
- });
53
50
  });
54
51
  room.on(RoomEvent.Disconnected, (reason) => {
55
52
  this.logger.warn("livekit: room disconnected", { reason });
@@ -262,6 +262,9 @@ var SignalingChannel = class {
262
262
  queueSize: msg.queue_size
263
263
  });
264
264
  break;
265
+ case "generation_started":
266
+ this.events.emit("generationStarted");
267
+ break;
265
268
  case "generation_tick":
266
269
  this.events.emit("generationTick", { seconds: msg.seconds });
267
270
  break;
@@ -165,7 +165,11 @@ var StreamSession = class {
165
165
  this.queue = qp;
166
166
  this.events.emit("queuePosition", qp);
167
167
  });
168
- this.signaling.on("generationTick", (e) => this.events.emit("generationTick", e));
168
+ this.signaling.on("generationStarted", () => this.markGenerating());
169
+ this.signaling.on("generationTick", (e) => {
170
+ this.markGenerating();
171
+ this.events.emit("generationTick", e);
172
+ });
169
173
  this.signaling.on("generationEnded", (e) => this.events.emit("generationEnded", e));
170
174
  this.signaling.on("serverError", (err) => this.events.emit("error", err));
171
175
  this.signaling.on("closed", (info) => this.handleConnectionLoss({
@@ -173,11 +177,11 @@ var StreamSession = class {
173
177
  ...info
174
178
  }));
175
179
  }
180
+ markGenerating() {
181
+ if (this.state === "connected") this.setState("generating");
182
+ }
176
183
  wireMediaEvents() {
177
184
  this.media.on("remoteStream", (stream) => this.events.emit("remoteStream", stream));
178
- this.media.on("firstFrame", () => {
179
- if (this.state === "connected") this.setState("generating");
180
- });
181
185
  this.media.on("disconnected", (info) => this.handleConnectionLoss({
182
186
  source: "media",
183
187
  reason: info.reason
@@ -81,11 +81,11 @@ const createRealTimeSubscribeClient = (opts) => {
81
81
  activeRoom.on(RoomEvent.TrackSubscribed, (track, _pub, participant) => {
82
82
  if (!participant.identity.startsWith(REALTIME_CONFIG.livekit.inferenceServerIdentityPrefix)) return;
83
83
  if (track.kind !== Track.Kind.Video && track.kind !== Track.Kind.Audio) return;
84
- track.attach();
85
84
  const mediaStreamTrack = track.mediaStreamTrack;
86
85
  if (!mediaStreamTrack) return;
87
- remoteStream ??= new MediaStream();
88
- if (!remoteStream.getTracks().includes(mediaStreamTrack)) remoteStream.addTrack(mediaStreamTrack);
86
+ const tracks = remoteStream?.getTracks() ?? [];
87
+ if (!tracks.includes(mediaStreamTrack)) tracks.push(mediaStreamTrack);
88
+ remoteStream = new MediaStream(tracks);
89
89
  options.onRemoteStream(remoteStream);
90
90
  });
91
91
  activeRoom.on(RoomEvent.ConnectionStateChanged, (state) => {
@@ -145,7 +145,7 @@ const proResolutionSchema = () => {
145
145
  */
146
146
  const v2vResolutionSchema = z.literal("720p").optional().describe("The resolution to use for the generation").default("720p");
147
147
  const videoEditSchema = z.object({
148
- prompt: z.string().min(1).max(1e3).describe("The prompt to use for the generation"),
148
+ prompt: z.string().min(1).describe("The prompt to use for the generation"),
149
149
  data: fileInputSchema.describe("The video data to use for generation (File, Blob, ReadableStream, URL, or string URL). Output video is limited to 5 seconds."),
150
150
  reference_image: fileInputSchema.optional().describe("Optional reference image to guide what to add to the video (File, Blob, ReadableStream, URL, or string URL)"),
151
151
  seed: z.number().optional().describe("The seed to use for the generation"),
@@ -161,7 +161,7 @@ const imageEditSchema = z.object({
161
161
  enhance_prompt: z.boolean().optional().describe("Whether to enhance the prompt")
162
162
  });
163
163
  const restyleSchema = z.object({
164
- prompt: z.string().min(1).max(1e3).optional().describe("Text prompt for the video editing"),
164
+ prompt: z.string().min(1).optional().describe("Text prompt for the video editing"),
165
165
  reference_image: fileInputSchema.optional().describe("Reference image to transform into a prompt (File, Blob, ReadableStream, URL, or string URL)"),
166
166
  data: fileInputSchema.describe("Video file to process (File, Blob, ReadableStream, URL, or string URL)"),
167
167
  seed: z.number().optional().describe("Seed for the video generation"),
@@ -169,7 +169,7 @@ const restyleSchema = z.object({
169
169
  enhance_prompt: z.boolean().optional().describe("Whether to enhance the prompt (only valid with text prompt, defaults to true on backend)")
170
170
  }).refine((data) => data.prompt !== void 0 !== (data.reference_image !== void 0), { message: "Must provide either 'prompt' or 'reference_image', but not both" }).refine((data) => !(data.reference_image !== void 0 && data.enhance_prompt !== void 0), { message: "'enhance_prompt' is only valid when using 'prompt', not 'reference_image'" });
171
171
  const videoEdit2Schema = z.object({
172
- prompt: z.string().max(1e3).describe("Text prompt for the video editing. Send an empty string if you want no text prompt."),
172
+ prompt: z.string().describe("Text prompt for the video editing. Send an empty string if you want no text prompt."),
173
173
  reference_image: fileInputSchema.optional().describe("Optional reference image to guide the edit (File, Blob, ReadableStream, URL, or string URL)"),
174
174
  data: fileInputSchema.describe("Video file to process (File, Blob, ReadableStream, URL, or string URL)"),
175
175
  seed: z.number().optional().describe("The seed to use for the generation"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decartai/sdk",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Decart's JavaScript SDK",
5
5
  "type": "module",
6
6
  "license": "MIT",