@reactor-team/js-sdk 2.11.1 → 2.11.2
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.mts +63 -1
- package/dist/index.d.ts +63 -1
- package/dist/index.js +81 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +81 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -91,7 +91,7 @@ import { z } from "zod";
|
|
|
91
91
|
// package.json
|
|
92
92
|
var package_default = {
|
|
93
93
|
name: "@reactor-team/js-sdk",
|
|
94
|
-
version: "2.11.
|
|
94
|
+
version: "2.11.2",
|
|
95
95
|
description: "Reactor JavaScript frontend SDK \u2014 connect React and TypeScript apps to real-time AI video models on Reactor.",
|
|
96
96
|
license: "Apache-2.0",
|
|
97
97
|
repository: {
|
|
@@ -403,6 +403,18 @@ var CoordinatorClient = class {
|
|
|
403
403
|
return parsed;
|
|
404
404
|
});
|
|
405
405
|
}
|
|
406
|
+
/**
|
|
407
|
+
* Attaches to a session created elsewhere (e.g. by a backend) instead of
|
|
408
|
+
* creating one via {@link createSession}. After this, {@link pollSessionReady}
|
|
409
|
+
* and {@link getSession} operate on the adopted id. The session must be owned
|
|
410
|
+
* by the account behind this client's JWT.
|
|
411
|
+
*/
|
|
412
|
+
adoptSession(sessionId) {
|
|
413
|
+
return __async(this, null, function* () {
|
|
414
|
+
this.currentSessionId = sessionId;
|
|
415
|
+
console.debug("[CoordinatorClient] Adopted existing session:", sessionId);
|
|
416
|
+
});
|
|
417
|
+
}
|
|
406
418
|
/**
|
|
407
419
|
* Polls GET /sessions/{id} until the Runtime has accepted the session
|
|
408
420
|
* and populated capabilities and selected_transport.
|
|
@@ -694,6 +706,48 @@ var LocalCoordinatorClient = class extends CoordinatorClient {
|
|
|
694
706
|
return CreateSessionResponseSchema.parse(data);
|
|
695
707
|
});
|
|
696
708
|
}
|
|
709
|
+
/**
|
|
710
|
+
* Adopts the local session for `connect({ sessionId })`: records the id and
|
|
711
|
+
* reads the session descriptor, caching it so {@link pollSessionReady}
|
|
712
|
+
* returns immediately. No `start_session` is issued.
|
|
713
|
+
*
|
|
714
|
+
* The local runtime hosts a single session (always id `"local"`), so the
|
|
715
|
+
* lookup ignores the specific id. This is a pure read of session info — it
|
|
716
|
+
* does not start or otherwise advance the session.
|
|
717
|
+
*/
|
|
718
|
+
adoptSession(sessionId) {
|
|
719
|
+
return __async(this, null, function* () {
|
|
720
|
+
this.currentSessionId = sessionId;
|
|
721
|
+
this.cachedSessionResponse = yield this.getSession();
|
|
722
|
+
console.debug(
|
|
723
|
+
"[LocalCoordinatorClient] Adopted existing session:",
|
|
724
|
+
sessionId
|
|
725
|
+
);
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
/**
|
|
729
|
+
* Reads the local session descriptor (model, capabilities, transport,
|
|
730
|
+
* state) via the runtime's read-only `GET /session`.
|
|
731
|
+
*
|
|
732
|
+
* The local runtime exposes a single session, so — unlike the Coordinator's
|
|
733
|
+
* id-addressed `GET /sessions/{id}` — there is no id in the path. Read-only:
|
|
734
|
+
* it does not start or advance the session.
|
|
735
|
+
*/
|
|
736
|
+
getSession() {
|
|
737
|
+
return __async(this, null, function* () {
|
|
738
|
+
const response = yield fetch(`${this.baseUrl}/session`, {
|
|
739
|
+
method: "GET",
|
|
740
|
+
headers: yield this.getHeaders(),
|
|
741
|
+
signal: this.signal
|
|
742
|
+
});
|
|
743
|
+
if (!response.ok) {
|
|
744
|
+
const errorText = yield response.text();
|
|
745
|
+
throw new Error(`Failed to get session: ${response.status} ${errorText}`);
|
|
746
|
+
}
|
|
747
|
+
const data = yield response.json();
|
|
748
|
+
return SessionResponseSchema.parse(data);
|
|
749
|
+
});
|
|
750
|
+
}
|
|
697
751
|
/**
|
|
698
752
|
* Returns the cached full session response immediately.
|
|
699
753
|
* The local runtime already provided everything in start_session.
|
|
@@ -2919,6 +2973,12 @@ var Reactor = class {
|
|
|
2919
2973
|
* be a static string or a {@link JwtSource} resolver; pass a
|
|
2920
2974
|
* resolver when the token is short-lived so each Coordinator HTTP
|
|
2921
2975
|
* hop sees a fresh value.
|
|
2976
|
+
*
|
|
2977
|
+
* Pass `options.sessionId` to attach to a session that already exists
|
|
2978
|
+
* (e.g. one created by a backend) instead of creating a new one — session
|
|
2979
|
+
* creation is skipped and the transport is brought up against that id. The
|
|
2980
|
+
* `jwtToken` must be valid for the account that owns the session. Works in
|
|
2981
|
+
* local mode too (it looks the session up by id rather than starting one).
|
|
2922
2982
|
*/
|
|
2923
2983
|
connect(jwtToken, options) {
|
|
2924
2984
|
return __async(this, null, function* () {
|
|
@@ -2940,20 +3000,29 @@ var Reactor = class {
|
|
|
2940
3000
|
jwtToken,
|
|
2941
3001
|
model: this.model
|
|
2942
3002
|
});
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
"[Reactor]
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
initialResponse.
|
|
2952
|
-
|
|
3003
|
+
let sessionCreationMs = 0;
|
|
3004
|
+
let sessionId;
|
|
3005
|
+
if (options == null ? void 0 : options.sessionId) {
|
|
3006
|
+
yield this.coordinatorClient.adoptSession(options.sessionId);
|
|
3007
|
+
sessionId = options.sessionId;
|
|
3008
|
+
console.debug("[Reactor] Attaching to existing session:", sessionId);
|
|
3009
|
+
} else {
|
|
3010
|
+
const tSession = performance.now();
|
|
3011
|
+
const initialResponse = yield this.coordinatorClient.createSession();
|
|
3012
|
+
sessionCreationMs = performance.now() - tSession;
|
|
3013
|
+
sessionId = initialResponse.session_id;
|
|
3014
|
+
console.debug(
|
|
3015
|
+
"[Reactor] Session created:",
|
|
3016
|
+
sessionId,
|
|
3017
|
+
"state:",
|
|
3018
|
+
initialResponse.state
|
|
3019
|
+
);
|
|
3020
|
+
}
|
|
3021
|
+
this.setSessionId(sessionId);
|
|
2953
3022
|
this.setStatus("waiting");
|
|
2954
3023
|
this.transportClient = new WebRTCTransportClient({
|
|
2955
3024
|
baseUrl: this.coordinatorUrl,
|
|
2956
|
-
sessionId
|
|
3025
|
+
sessionId,
|
|
2957
3026
|
jwtToken: this.local ? "local" : jwtToken,
|
|
2958
3027
|
webrtcVersion: REACTOR_WEBRTC_VERSION,
|
|
2959
3028
|
maxPollAttempts: options == null ? void 0 : options.maxAttempts
|