@decartai/sdk 0.1.6 → 0.1.8

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.
@@ -15,6 +15,7 @@ declare const realTimeClientInitialStateSchema: z.ZodObject<{
15
15
  enhance: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
16
16
  }, z.core.$strip>>;
17
17
  image: z.ZodOptional<z.ZodUnion<readonly [z.ZodCustom<Blob, Blob>, z.ZodCustom<File, File>, z.ZodString]>>;
18
+ passthrough: z.ZodOptional<z.ZodBoolean>;
18
19
  }, z.core.$strip>;
19
20
  type OnRemoteStreamFn = (stream: MediaStream) => void;
20
21
  type OnConnectionChangeFn = (state: ConnectionState) => void;
@@ -46,6 +47,7 @@ declare const realTimeClientConnectOptionsSchema: z.ZodObject<{
46
47
  enhance: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
47
48
  }, z.core.$strip>>;
48
49
  image: z.ZodOptional<z.ZodUnion<readonly [z.ZodCustom<Blob, Blob>, z.ZodCustom<File, File>, z.ZodString]>>;
50
+ passthrough: z.ZodOptional<z.ZodBoolean>;
49
51
  }, z.core.$strip>>;
50
52
  queryParams: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
51
53
  mirror: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"auto">, z.ZodBoolean]>>;
@@ -89,6 +89,7 @@ const createRealTimeClient = (opts) => {
89
89
  initialImage,
90
90
  initialImageRef,
91
91
  initialPrompt,
92
+ initialPassthrough: initialState?.passthrough,
92
93
  logger,
93
94
  videoCodec: publishCodec
94
95
  });
@@ -63,14 +63,19 @@ var SignalingChannel = class {
63
63
  this.config.observability?.startPhase("room-join");
64
64
  const roomInfoWait = this.waitForRoomInfo(handshakeTimeout);
65
65
  const initialStateRequest = buildInitialStateRequest(opts.initialState);
66
+ const userSetInitialState = opts.initialState != null && (opts.initialState.image != null || opts.initialState.imageRef != null || opts.initialState.prompt != null);
66
67
  const joinMessage = {
67
68
  type: "livekit_join",
68
- initial_state: initialStateRequest ? initialStateRequest.message : null
69
+ passthrough: opts.passthrough ?? !userSetInitialState
69
70
  };
70
71
  if (!this.writeMessage(joinMessage)) {
71
72
  roomInfoWait.cancel();
72
73
  throw new Error("WebSocket is not open");
73
74
  }
75
+ if (initialStateRequest && !this.writeMessage(initialStateRequest.message)) {
76
+ roomInfoWait.cancel();
77
+ throw new Error("WebSocket is not open");
78
+ }
74
79
  let roomInfo;
75
80
  try {
76
81
  roomInfo = await roomInfoWait.promise;
@@ -1,6 +1,5 @@
1
1
  import { createConsoleLogger } from "../utils/logger.js";
2
2
  import { REALTIME_CONFIG } from "./config-realtime.js";
3
- import { InitialStateGate } from "./initial-state-gate.js";
4
3
  import { MediaChannel } from "./media-channel.js";
5
4
  import { SignalingChannel } from "./signaling-channel.js";
6
5
  import mitt from "mitt";
@@ -25,7 +24,7 @@ var StreamSession = class {
25
24
  queue = null;
26
25
  disposed = false;
27
26
  currentAttempt = 0;
28
- initialStateGate = new InitialStateGate();
27
+ teardownGeneration = 0;
29
28
  logger;
30
29
  constructor(config) {
31
30
  this.config = config;
@@ -102,11 +101,12 @@ var StreamSession = class {
102
101
  const initialState = this.getInitialState();
103
102
  this.config.observability?.beginConnectionBreakdown(attempt, getInitialImageSizeKb(initialState?.image));
104
103
  this.config.observability?.markGlassToGlassStart();
105
- const gateAttempt = this.initialStateGate.startAttempt(initialState);
106
104
  const { roomInfo, initialStateAck } = await this.signaling.openAndJoin({
107
105
  connectTimeout: REALTIME_CONFIG.session.connectionTimeoutMs,
108
- initialState
106
+ initialState,
107
+ passthrough: this.config.initialPassthrough
109
108
  });
109
+ this.watchInitialStateAck(initialStateAck, attempt);
110
110
  if (this.disposed || this.currentAttempt !== attempt) {
111
111
  this.tearDown();
112
112
  throw new AbortError("Stale connect attempt");
@@ -117,7 +117,6 @@ var StreamSession = class {
117
117
  url: roomInfo.livekitUrl,
118
118
  token: roomInfo.token
119
119
  });
120
- if (!await gateAttempt.waitForReadiness(initialStateAck)) throw new AbortError("Stale connect attempt");
121
120
  await this.media.publishLocalTracks();
122
121
  } catch (error) {
123
122
  this.tearDown();
@@ -141,6 +140,13 @@ var StreamSession = class {
141
140
  throw error;
142
141
  }
143
142
  }
143
+ watchInitialStateAck(initialStateAck, attempt) {
144
+ const generation = this.teardownGeneration;
145
+ initialStateAck.catch((error) => {
146
+ if (this.disposed || this.currentAttempt !== attempt || this.teardownGeneration !== generation) return;
147
+ this.events.emit("error", error instanceof Error ? error : new Error(String(error)));
148
+ });
149
+ }
144
150
  getInitialState() {
145
151
  if (this.config.initialImageRef !== void 0) return {
146
152
  imageRef: this.config.initialImageRef,
@@ -240,9 +246,9 @@ var StreamSession = class {
240
246
  this.wireMediaEvents();
241
247
  }
242
248
  tearDown() {
249
+ this.teardownGeneration++;
243
250
  this.signaling.close();
244
251
  this.media.disconnect();
245
- this.initialStateGate.reset();
246
252
  this.resetHandshakeState();
247
253
  }
248
254
  resetHandshakeState() {
@@ -7,6 +7,7 @@ declare const modelStateSchema: z.ZodObject<{
7
7
  enhance: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
8
8
  }, z.core.$strip>>;
9
9
  image: z.ZodOptional<z.ZodUnion<readonly [z.ZodCustom<Blob, Blob>, z.ZodCustom<File, File>, z.ZodString]>>;
10
+ passthrough: z.ZodOptional<z.ZodBoolean>;
10
11
  }, z.core.$strip>;
11
12
  type ModelState = z.infer<typeof modelStateSchema>;
12
13
  //#endregion
@@ -9,7 +9,8 @@ const modelStateSchema = z.object({
9
9
  z.instanceof(Blob),
10
10
  z.instanceof(File),
11
11
  z.string()
12
- ]).optional()
12
+ ]).optional(),
13
+ passthrough: z.boolean().optional()
13
14
  });
14
15
  //#endregion
15
16
  export { modelStateSchema };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decartai/sdk",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Decart's JavaScript SDK",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,21 +0,0 @@
1
- //#region src/realtime/initial-state-gate.ts
2
- var InitialStateGate = class {
3
- attemptId = 0;
4
- startAttempt(initialState) {
5
- const attemptId = ++this.attemptId;
6
- const shouldWait = hasCallerProvidedInitialState(initialState);
7
- return { waitForReadiness: async (initialStateAck) => {
8
- if (shouldWait) await initialStateAck;
9
- return this.attemptId === attemptId;
10
- } };
11
- }
12
- reset() {
13
- this.attemptId++;
14
- }
15
- };
16
- function hasCallerProvidedInitialState(state) {
17
- if (!state) return false;
18
- return state.image !== void 0 && state.image !== null || state.prompt !== void 0 && state.prompt !== null;
19
- }
20
- //#endregion
21
- export { InitialStateGate };