@decartai/sdk 0.1.8 → 0.1.9

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.
@@ -98,6 +98,7 @@ type RealTimeClient = {
98
98
  * - `null`: clear the current image.
99
99
  */
100
100
  setImage: (image: Blob | File | string | null, options?: ImageSetOptions) => Promise<void>;
101
+ replaceVideoTrack: (track: MediaStreamTrack) => Promise<void>;
101
102
  };
102
103
  //#endregion
103
104
  export { Events, RealTimeClient, RealTimeClientConnectOptions, RealTimeClientInitialState };
@@ -64,6 +64,13 @@ var MediaChannel = class {
64
64
  await this.publishTracks(this.config.localStream);
65
65
  this.config.observability?.endPhase("publish-local-track", { success: true });
66
66
  }
67
+ async replaceVideoTrack(track) {
68
+ const room = this.room;
69
+ if (!room) throw new Error("Cannot replace video track: media channel is not connected");
70
+ const videoTrack = [...room.localParticipant.videoTrackPublications.values()][0]?.videoTrack;
71
+ if (!videoTrack) throw new Error("Cannot replace video track: no published video track");
72
+ await videoTrack.replaceTrack(track);
73
+ }
67
74
  disconnect() {
68
75
  const room = this.room;
69
76
  this.room = null;
@@ -50,9 +50,13 @@ const realtimeMethods = (session, imageToBase64) => {
50
50
  timeout: REALTIME_CONFIG.methods.promptTimeoutMs
51
51
  });
52
52
  };
53
+ const replaceVideoTrack = async (track) => {
54
+ await session.replaceVideoTrack(track);
55
+ };
53
56
  return {
54
57
  set,
55
- setPrompt
58
+ setPrompt,
59
+ replaceVideoTrack
56
60
  };
57
61
  };
58
62
  //#endregion
@@ -71,6 +71,12 @@ var StreamSession = class {
71
71
  this.assertConnected();
72
72
  return this.signaling.setImage(payload, opts);
73
73
  }
74
+ async replaceVideoTrack(track) {
75
+ this.assertConnected();
76
+ await this.media.replaceVideoTrack(track);
77
+ const previous = this.config.localStream;
78
+ this.config.localStream = new MediaStream(previous ? [track, ...previous.getAudioTracks()] : [track]);
79
+ }
74
80
  disconnect() {
75
81
  this.disposed = true;
76
82
  this.tearDown();
@@ -162,10 +168,6 @@ var StreamSession = class {
162
168
  prompt: this.config.initialPrompt.text,
163
169
  enhance: this.config.initialPrompt.enhance
164
170
  };
165
- if (this.config.localStream) return {
166
- image: null,
167
- prompt: null
168
- };
169
171
  }
170
172
  wireSignalingEvents() {
171
173
  this.signaling.on("queuePosition", (qp) => {
@@ -25,6 +25,8 @@ type CreateTokenOptions = {
25
25
  };
26
26
  type CreateTokenResponse = {
27
27
  apiKey: string;
28
+ /** Signed JWT mirroring `apiKey`, verifiable offline via the public JWKS. */
29
+ token?: string;
28
30
  expiresAt: string;
29
31
  /** Present when `allowedModels` and/or `allowedOrigins` were set on the request. */
30
32
  permissions?: {
@@ -48,7 +50,7 @@ type TokensClient = {
48
50
  * ```ts
49
51
  * const client = createDecartClient({ apiKey: process.env.DECART_API_KEY });
50
52
  * const token = await client.tokens.create();
51
- * // Returns: { apiKey: "ek_...", expiresAt: "2024-12-15T12:10:00Z" }
53
+ * // Returns: { apiKey: "ek_...", token: "eyJhbGciOiJFZERTQS...", expiresAt: "2024-12-15T12:10:00Z" }
52
54
  *
53
55
  * // With metadata:
54
56
  * const token = await client.tokens.create({ metadata: { role: "viewer" } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decartai/sdk",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "Decart's JavaScript SDK",
5
5
  "type": "module",
6
6
  "license": "MIT",