@escapeaihq/client-core 0.7.0 → 0.12.0
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/README.md +22 -3
- package/dist/api.d.ts +114 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +62 -47
- package/dist/api.js.map +1 -1
- package/dist/graphSchema.d.ts +72 -0
- package/dist/graphSchema.d.ts.map +1 -0
- package/dist/graphSchema.js +105 -0
- package/dist/graphSchema.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/reactor/abortUtils.d.ts +16 -0
- package/dist/reactor/abortUtils.d.ts.map +1 -0
- package/dist/reactor/abortUtils.js +26 -0
- package/dist/reactor/abortUtils.js.map +1 -0
- package/dist/reactor/applyScenePrompt.d.ts +75 -0
- package/dist/reactor/applyScenePrompt.d.ts.map +1 -0
- package/dist/reactor/applyScenePrompt.js +60 -0
- package/dist/reactor/applyScenePrompt.js.map +1 -0
- package/dist/reactor/heliosCommandDispatcher.d.ts.map +1 -1
- package/dist/reactor/heliosCommandDispatcher.js +10 -15
- package/dist/reactor/heliosCommandDispatcher.js.map +1 -1
- package/dist/reactor/index.d.ts +2 -0
- package/dist/reactor/index.d.ts.map +1 -1
- package/dist/reactor/index.js +2 -0
- package/dist/reactor/index.js.map +1 -1
- package/dist/reactor/sceneEntry.d.ts +40 -6
- package/dist/reactor/sceneEntry.d.ts.map +1 -1
- package/dist/reactor/sceneEntry.js +63 -24
- package/dist/reactor/sceneEntry.js.map +1 -1
- package/dist/reactor/seedImageOrchestrator.d.ts +45 -2
- package/dist/reactor/seedImageOrchestrator.d.ts.map +1 -1
- package/dist/reactor/seedImageOrchestrator.js +174 -4
- package/dist/reactor/seedImageOrchestrator.js.map +1 -1
- package/dist/timeFormat.d.ts +10 -0
- package/dist/timeFormat.d.ts.map +1 -1
- package/dist/timeFormat.js +12 -0
- package/dist/timeFormat.js.map +1 -1
- package/dist/toolSchemas.d.ts +370 -0
- package/dist/toolSchemas.d.ts.map +1 -0
- package/dist/toolSchemas.js +182 -0
- package/dist/toolSchemas.js.map +1 -0
- package/dist/vision/VisionPublisher.d.ts +115 -0
- package/dist/vision/VisionPublisher.d.ts.map +1 -0
- package/dist/vision/VisionPublisher.js +475 -0
- package/dist/vision/VisionPublisher.js.map +1 -0
- package/dist/vision/credentials.d.ts +22 -0
- package/dist/vision/credentials.d.ts.map +1 -0
- package/dist/vision/credentials.js +34 -0
- package/dist/vision/credentials.js.map +1 -0
- package/dist/vision/index.d.ts +14 -0
- package/dist/vision/index.d.ts.map +1 -0
- package/dist/vision/index.js +11 -0
- package/dist/vision/index.js.map +1 -0
- package/dist/vision/startVisionPublisher.d.ts +38 -0
- package/dist/vision/startVisionPublisher.d.ts.map +1 -0
- package/dist/vision/startVisionPublisher.js +44 -0
- package/dist/vision/startVisionPublisher.js.map +1 -0
- package/dist/vision/types.d.ts +95 -0
- package/dist/vision/types.d.ts.map +1 -0
- package/dist/vision/types.js +12 -0
- package/dist/vision/types.js.map +1 -0
- package/dist/vision/visionScheduler.d.ts +63 -0
- package/dist/vision/visionScheduler.d.ts.map +1 -0
- package/dist/vision/visionScheduler.js +67 -0
- package/dist/vision/visionScheduler.js.map +1 -0
- package/dist/websocket.d.ts +153 -0
- package/dist/websocket.d.ts.map +1 -1
- package/dist/websocket.js +199 -1
- package/dist/websocket.js.map +1 -1
- package/package.json +11 -1
- package/src/__tests__/api-pollers.test.ts +100 -0
- package/src/__tests__/chat-auth.test.ts +91 -0
- package/src/__tests__/graphSchema.test.ts +117 -0
- package/src/__tests__/reactor/applyScenePrompt.test.ts +192 -0
- package/src/__tests__/reactor/heliosCommandDispatcher.test.ts +4 -3
- package/src/__tests__/reactor/sceneEntry.test.ts +134 -10
- package/src/__tests__/reactor/seedImageOrchestrator.test.ts +51 -16
- package/src/__tests__/timeFormat.test.ts +22 -1
- package/src/__tests__/toolSchemas.test.ts +57 -0
- package/src/__tests__/websocket-vision.test.ts +265 -0
- package/src/__tests__/websocket.test.ts +75 -0
- package/src/api.ts +160 -47
- package/src/graphSchema.ts +149 -0
- package/src/index.ts +3 -0
- package/src/reactor/abortUtils.ts +22 -0
- package/src/reactor/applyScenePrompt.ts +136 -0
- package/src/reactor/heliosCommandDispatcher.ts +10 -18
- package/src/reactor/index.ts +2 -0
- package/src/reactor/sceneEntry.ts +104 -33
- package/src/reactor/seedImageOrchestrator.ts +201 -4
- package/src/timeFormat.ts +13 -0
- package/src/toolSchemas.ts +225 -0
- package/src/vision/VisionPublisher.ts +553 -0
- package/src/vision/__tests__/VisionPublisher.kvs.test.ts +244 -0
- package/src/vision/__tests__/VisionPublisher.test.ts +301 -0
- package/src/vision/__tests__/startVisionPublisher.test.ts +251 -0
- package/src/vision/__tests__/toVisionRtcCredentials.test.ts +113 -0
- package/src/vision/__tests__/visionScheduler.test.ts +149 -0
- package/src/vision/credentials.ts +39 -0
- package/src/vision/index.ts +31 -0
- package/src/vision/startVisionPublisher.ts +64 -0
- package/src/vision/types.ts +101 -0
- package/src/vision/visionScheduler.ts +102 -0
- package/src/websocket.ts +301 -1
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework-agnostic WebRTC vision publisher.
|
|
3
|
+
*
|
|
4
|
+
* Lifecycle:
|
|
5
|
+
* - `start()` opens an `RTCPeerConnection`, attaches the video track,
|
|
6
|
+
* creates an SDP offer, ships it to the backend over the
|
|
7
|
+
* authenticated `ChatWebSocket`, and listens for the answer + ICE.
|
|
8
|
+
* - `stop()` closes the peer connection, removes WS event listeners,
|
|
9
|
+
* and notifies the backend with a `vision_close` so it can free
|
|
10
|
+
* its `FrameBuffer` and aiortc receiver.
|
|
11
|
+
*
|
|
12
|
+
* Auto-restart: if `pc.connectionState` transitions to `'failed'`, the
|
|
13
|
+
* publisher emits an error and tears down. Restart-on-failure is the
|
|
14
|
+
* caller's responsibility (React hook / Vue composable) — that keeps
|
|
15
|
+
* this class free of timer/retry state and easy to test in isolation.
|
|
16
|
+
*
|
|
17
|
+
* Wire-shape source of truth: `shared/vision_protocol.py`. Camel-case
|
|
18
|
+
* field names live here; the `ChatWebSocket` boundary converts to
|
|
19
|
+
* snake_case before sending and back to camel-case on receive.
|
|
20
|
+
*
|
|
21
|
+
* Spec: `specs/2026-05-22-phase-2-multimodal-watch.md`.
|
|
22
|
+
*/
|
|
23
|
+
import type { VisionErrorListener, VisionPublisherOptions, VisionStatusListener } from './types';
|
|
24
|
+
export declare class VisionPublisher {
|
|
25
|
+
private readonly ws;
|
|
26
|
+
private readonly track;
|
|
27
|
+
private readonly fps;
|
|
28
|
+
private readonly iceServers;
|
|
29
|
+
private readonly credentials;
|
|
30
|
+
private pc;
|
|
31
|
+
private kvsSignalingClient;
|
|
32
|
+
private statusListeners;
|
|
33
|
+
private errorListeners;
|
|
34
|
+
private wsHandlers;
|
|
35
|
+
private stopped;
|
|
36
|
+
constructor(opts: VisionPublisherOptions);
|
|
37
|
+
/**
|
|
38
|
+
* Default ICE server set when neither `credentials.iceServers` nor
|
|
39
|
+
* `config.iceServers` is provided.
|
|
40
|
+
*
|
|
41
|
+
* Includes a single public STUN server so the browser can generate
|
|
42
|
+
* server-reflexive (`srflx`) candidates. This is required for
|
|
43
|
+
* connectivity in local-dev (browser ↔ Python on the same host) where
|
|
44
|
+
* aiortc may not advertise a candidate the browser can route to
|
|
45
|
+
* directly. In production, `credentials.iceServers` returned by the
|
|
46
|
+
* `/vision-rtc/credentials` endpoint carries KVS-managed STUN + TURN
|
|
47
|
+
* URIs, so this default is only the fallback path. Privacy-sensitive
|
|
48
|
+
* callers can still pass `iceServers: []` via `config` to skip STUN
|
|
49
|
+
* entirely.
|
|
50
|
+
*/
|
|
51
|
+
static readonly DEFAULT_ICE_SERVERS: RTCIceServer[];
|
|
52
|
+
/**
|
|
53
|
+
* Open the peer connection. Routing is mode-aware:
|
|
54
|
+
*
|
|
55
|
+
* - **No credentials passed OR `credentials.mode === 'local'`**: the
|
|
56
|
+
* publisher uses the existing chat-WS protocol (`vision_offer` /
|
|
57
|
+
* `vision_ice` / `vision_close`). No AWS dependency. Default for
|
|
58
|
+
* local-dev (`WEBRTC_SIGNALING_MODE=local`).
|
|
59
|
+
* - **`credentials.mode === 'kvs'`**: the publisher dynamically
|
|
60
|
+
* imports the Amazon KVS WebRTC SDK and opens the signed wss:// URL
|
|
61
|
+
* from `credentials.signedSignalingUrl`. Used in deployed
|
|
62
|
+
* environments.
|
|
63
|
+
*
|
|
64
|
+
* The two paths share the same `RTCPeerConnection` setup, status /
|
|
65
|
+
* error event surface, and `stop()` teardown. Only signaling differs.
|
|
66
|
+
*/
|
|
67
|
+
start(): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Local-mode signaling: SDP offer/answer + ICE trickle go through the
|
|
70
|
+
* authenticated chat-WS. The backend's `ws.py` `_handle_vision_offer`
|
|
71
|
+
* etc. accept them.
|
|
72
|
+
*/
|
|
73
|
+
private startLocalMode;
|
|
74
|
+
/**
|
|
75
|
+
* KVS-mode signaling: SDP offer/answer + ICE trickle flow through
|
|
76
|
+
* an Amazon KVS WebRTC signaling channel. The SDK is dynamically
|
|
77
|
+
* imported so local-only builds (which never set `credentials.mode
|
|
78
|
+
* === 'kvs'`) don't pay the bundle cost.
|
|
79
|
+
*
|
|
80
|
+
* The signed wss:// URL the backend mints is what the SDK opens —
|
|
81
|
+
* raw AWS credentials never reach the browser. ICE servers in
|
|
82
|
+
* `credentials.iceServers` include the KVS-managed STUN entry plus
|
|
83
|
+
* any short-term TURN entries (`expiresIn` seconds). Callers must
|
|
84
|
+
* re-fetch credentials before that elapses if a session outlives
|
|
85
|
+
* the TTL; this publisher does not auto-refresh.
|
|
86
|
+
*
|
|
87
|
+
* **Async timing note:** the SDP offer is NOT sent inline with
|
|
88
|
+
* `start()`. The KVS SignalingClient uses an EventEmitter pattern —
|
|
89
|
+
* we subscribe to its `open` event and send the offer from inside
|
|
90
|
+
* that handler. So `start()` returns to the caller before the offer
|
|
91
|
+
* has been created or sent (an event loop tick or two later). Code
|
|
92
|
+
* that calls `start()` and synchronously checks `pc.signalingState`
|
|
93
|
+
* will see `"stable"` (no offer yet). This is observable but
|
|
94
|
+
* intentional — chat turns fired in the window between `start()`
|
|
95
|
+
* and `open` correctly resolve to "no vision frame this turn" via
|
|
96
|
+
* `session.kvs_client_id === None` server-side.
|
|
97
|
+
*/
|
|
98
|
+
private startKvsMode;
|
|
99
|
+
/**
|
|
100
|
+
* Tear down the peer connection, unsubscribe from WS events, and let
|
|
101
|
+
* the backend know via `vision_close` so it can free its receiver.
|
|
102
|
+
* Idempotent — safe to call from `finally` blocks or auto-restart
|
|
103
|
+
* paths.
|
|
104
|
+
*/
|
|
105
|
+
stop(): void;
|
|
106
|
+
/** Subscribe to backend `vision_status` updates (HUD telemetry). Returns
|
|
107
|
+
* an unsubscribe function so React effects can clean up. */
|
|
108
|
+
onStatus(listener: VisionStatusListener): () => void;
|
|
109
|
+
/** Subscribe to publisher-level errors (peer-connection failure, SDP /
|
|
110
|
+
* ICE rejection). Returns an unsubscribe function. */
|
|
111
|
+
onError(listener: VisionErrorListener): () => void;
|
|
112
|
+
private emitError;
|
|
113
|
+
private static resolveTrack;
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=VisionPublisher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VisionPublisher.d.ts","sourceRoot":"","sources":["../../src/vision/VisionPublisher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,OAAO,KAAK,EACV,mBAAmB,EACnB,sBAAsB,EAGtB,oBAAoB,EACrB,MAAM,SAAS,CAAC;AAwCjB,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAgB;IACnC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAmB;IACzC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAiB;IAC5C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA8B;IAC1D,OAAO,CAAC,EAAE,CAAkC;IAC5C,OAAO,CAAC,kBAAkB,CAAuC;IACjE,OAAO,CAAC,eAAe,CAA8B;IACrD,OAAO,CAAC,cAAc,CAA6B;IACnD,OAAO,CAAC,UAAU,CAAmE;IACrF,OAAO,CAAC,OAAO,CAAS;gBAEZ,IAAI,EAAE,sBAAsB;IAcxC;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,QAAQ,CAAC,mBAAmB,EAAE,YAAY,EAAE,CAEjD;IAEF;;;;;;;;;;;;;;OAcG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAgB5B;;;;OAIG;YACW,cAAc;IA0G5B;;;;;;;;;;;;;;;;;;;;;;;OAuBG;YACW,YAAY;IAkL1B;;;;;OAKG;IACH,IAAI,IAAI,IAAI;IA+CZ;gEAC4D;IAC5D,QAAQ,CAAC,QAAQ,EAAE,oBAAoB,GAAG,MAAM,IAAI;IAOpD;0DACsD;IACtD,OAAO,CAAC,QAAQ,EAAE,mBAAmB,GAAG,MAAM,IAAI;IAOlD,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,MAAM,CAAC,YAAY;CAkB5B"}
|
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework-agnostic WebRTC vision publisher.
|
|
3
|
+
*
|
|
4
|
+
* Lifecycle:
|
|
5
|
+
* - `start()` opens an `RTCPeerConnection`, attaches the video track,
|
|
6
|
+
* creates an SDP offer, ships it to the backend over the
|
|
7
|
+
* authenticated `ChatWebSocket`, and listens for the answer + ICE.
|
|
8
|
+
* - `stop()` closes the peer connection, removes WS event listeners,
|
|
9
|
+
* and notifies the backend with a `vision_close` so it can free
|
|
10
|
+
* its `FrameBuffer` and aiortc receiver.
|
|
11
|
+
*
|
|
12
|
+
* Auto-restart: if `pc.connectionState` transitions to `'failed'`, the
|
|
13
|
+
* publisher emits an error and tears down. Restart-on-failure is the
|
|
14
|
+
* caller's responsibility (React hook / Vue composable) — that keeps
|
|
15
|
+
* this class free of timer/retry state and easy to test in isolation.
|
|
16
|
+
*
|
|
17
|
+
* Wire-shape source of truth: `shared/vision_protocol.py`. Camel-case
|
|
18
|
+
* field names live here; the `ChatWebSocket` boundary converts to
|
|
19
|
+
* snake_case before sending and back to camel-case on receive.
|
|
20
|
+
*
|
|
21
|
+
* Spec: `specs/2026-05-22-phase-2-multimodal-watch.md`.
|
|
22
|
+
*/
|
|
23
|
+
const DEFAULT_FPS = 1.0;
|
|
24
|
+
export class VisionPublisher {
|
|
25
|
+
ws;
|
|
26
|
+
track;
|
|
27
|
+
fps;
|
|
28
|
+
iceServers;
|
|
29
|
+
credentials;
|
|
30
|
+
pc = null;
|
|
31
|
+
kvsSignalingClient = null;
|
|
32
|
+
statusListeners = [];
|
|
33
|
+
errorListeners = [];
|
|
34
|
+
wsHandlers = [];
|
|
35
|
+
stopped = false;
|
|
36
|
+
constructor(opts) {
|
|
37
|
+
this.ws = opts.ws;
|
|
38
|
+
this.track = VisionPublisher.resolveTrack(opts.track);
|
|
39
|
+
this.fps = opts.config?.fps ?? DEFAULT_FPS;
|
|
40
|
+
this.credentials = opts.credentials ?? null;
|
|
41
|
+
// Prefer KVS-provided ICE servers when credentials carry them;
|
|
42
|
+
// fall back to the caller's explicit override, then the public
|
|
43
|
+
// STUN default for legacy callers.
|
|
44
|
+
this.iceServers =
|
|
45
|
+
this.credentials?.iceServers ??
|
|
46
|
+
opts.config?.iceServers ??
|
|
47
|
+
VisionPublisher.DEFAULT_ICE_SERVERS;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Default ICE server set when neither `credentials.iceServers` nor
|
|
51
|
+
* `config.iceServers` is provided.
|
|
52
|
+
*
|
|
53
|
+
* Includes a single public STUN server so the browser can generate
|
|
54
|
+
* server-reflexive (`srflx`) candidates. This is required for
|
|
55
|
+
* connectivity in local-dev (browser ↔ Python on the same host) where
|
|
56
|
+
* aiortc may not advertise a candidate the browser can route to
|
|
57
|
+
* directly. In production, `credentials.iceServers` returned by the
|
|
58
|
+
* `/vision-rtc/credentials` endpoint carries KVS-managed STUN + TURN
|
|
59
|
+
* URIs, so this default is only the fallback path. Privacy-sensitive
|
|
60
|
+
* callers can still pass `iceServers: []` via `config` to skip STUN
|
|
61
|
+
* entirely.
|
|
62
|
+
*/
|
|
63
|
+
static DEFAULT_ICE_SERVERS = [
|
|
64
|
+
{ urls: 'stun:stun.l.google.com:19302' },
|
|
65
|
+
];
|
|
66
|
+
/**
|
|
67
|
+
* Open the peer connection. Routing is mode-aware:
|
|
68
|
+
*
|
|
69
|
+
* - **No credentials passed OR `credentials.mode === 'local'`**: the
|
|
70
|
+
* publisher uses the existing chat-WS protocol (`vision_offer` /
|
|
71
|
+
* `vision_ice` / `vision_close`). No AWS dependency. Default for
|
|
72
|
+
* local-dev (`WEBRTC_SIGNALING_MODE=local`).
|
|
73
|
+
* - **`credentials.mode === 'kvs'`**: the publisher dynamically
|
|
74
|
+
* imports the Amazon KVS WebRTC SDK and opens the signed wss:// URL
|
|
75
|
+
* from `credentials.signedSignalingUrl`. Used in deployed
|
|
76
|
+
* environments.
|
|
77
|
+
*
|
|
78
|
+
* The two paths share the same `RTCPeerConnection` setup, status /
|
|
79
|
+
* error event surface, and `stop()` teardown. Only signaling differs.
|
|
80
|
+
*/
|
|
81
|
+
async start() {
|
|
82
|
+
// Re-entry guard: a second start() without an intervening stop()
|
|
83
|
+
// would replace `this.pc` and `this.wsHandlers` without tearing
|
|
84
|
+
// down the prior PC/listeners — those would leak permanently on
|
|
85
|
+
// the long-lived ChatWebSocket. Force a clean slate first.
|
|
86
|
+
if (this.pc || this.wsHandlers.length > 0 || this.kvsSignalingClient) {
|
|
87
|
+
this.stop();
|
|
88
|
+
}
|
|
89
|
+
this.stopped = false;
|
|
90
|
+
if (this.credentials?.mode === 'kvs') {
|
|
91
|
+
await this.startKvsMode();
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
await this.startLocalMode();
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Local-mode signaling: SDP offer/answer + ICE trickle go through the
|
|
98
|
+
* authenticated chat-WS. The backend's `ws.py` `_handle_vision_offer`
|
|
99
|
+
* etc. accept them.
|
|
100
|
+
*/
|
|
101
|
+
async startLocalMode() {
|
|
102
|
+
// Defensive clear in case a prior session left handlers attached.
|
|
103
|
+
// ``stop()`` already unsubscribes them, but a socket that closes
|
|
104
|
+
// between ``stop()`` calling ``ws.off()`` and the off taking
|
|
105
|
+
// effect could leave stale listeners alive. Re-clearing here
|
|
106
|
+
// ensures a fresh ``start()`` never doubles up on dispatches.
|
|
107
|
+
this.wsHandlers = [];
|
|
108
|
+
const pc = new RTCPeerConnection({ iceServers: this.iceServers });
|
|
109
|
+
this.pc = pc;
|
|
110
|
+
pc.addEventListener('icecandidate', (ev) => {
|
|
111
|
+
const candidate = ev.candidate;
|
|
112
|
+
if (!candidate) {
|
|
113
|
+
// End-of-candidates sentinel. The backend expects an explicit
|
|
114
|
+
// `null` candidate to know trickle ICE is finished.
|
|
115
|
+
this.ws.sendVisionIce({ action: 'vision_ice', candidate: null });
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
this.ws.sendVisionIce({
|
|
119
|
+
action: 'vision_ice',
|
|
120
|
+
candidate: candidate.candidate,
|
|
121
|
+
sdpMid: candidate.sdpMid ?? null,
|
|
122
|
+
sdpMLineIndex: candidate.sdpMLineIndex ?? null,
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
pc.addEventListener('connectionstatechange', () => {
|
|
126
|
+
if (!this.pc)
|
|
127
|
+
return;
|
|
128
|
+
if (this.pc.connectionState === 'failed' && !this.stopped) {
|
|
129
|
+
this.emitError(new Error('VisionPublisher peer connection failed'));
|
|
130
|
+
this.stop();
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
pc.addTrack(this.track);
|
|
134
|
+
const onAnswer = async (msg) => {
|
|
135
|
+
if (!this.pc)
|
|
136
|
+
return;
|
|
137
|
+
const { sdp } = msg;
|
|
138
|
+
try {
|
|
139
|
+
await this.pc.setRemoteDescription({ type: 'answer', sdp });
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
// setRemoteDescription failure leaves the PC in an invalid
|
|
143
|
+
// signaling state — subsequent ICE/SDP calls would fail with
|
|
144
|
+
// cryptic "wrong state" errors that obscure the real cause.
|
|
145
|
+
// Force a clean teardown so the next start() builds a fresh PC.
|
|
146
|
+
this.emitError(err instanceof Error ? err : new Error(String(err)));
|
|
147
|
+
this.stop();
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
const onIce = async (msg) => {
|
|
151
|
+
if (!this.pc)
|
|
152
|
+
return;
|
|
153
|
+
const ice = msg;
|
|
154
|
+
if (!ice.candidate) {
|
|
155
|
+
// null candidate = end-of-candidates from the server; nothing to add.
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
try {
|
|
159
|
+
await this.pc.addIceCandidate({
|
|
160
|
+
candidate: ice.candidate,
|
|
161
|
+
sdpMid: ice.sdpMid ?? undefined,
|
|
162
|
+
sdpMLineIndex: ice.sdpMLineIndex ?? undefined,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
catch (err) {
|
|
166
|
+
// ICE candidate failure is recoverable (other candidates may
|
|
167
|
+
// succeed) — emit but don't tear down the connection.
|
|
168
|
+
this.emitError(err instanceof Error ? err : new Error(String(err)));
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
const onStatus = (msg) => {
|
|
172
|
+
const status = msg;
|
|
173
|
+
const payload = {
|
|
174
|
+
bufferedFrames: status.bufferedFrames,
|
|
175
|
+
processingPaused: status.processingPaused,
|
|
176
|
+
};
|
|
177
|
+
for (const listener of this.statusListeners)
|
|
178
|
+
listener(payload);
|
|
179
|
+
};
|
|
180
|
+
this.ws.on('vision_answer', onAnswer);
|
|
181
|
+
this.ws.on('vision_ice', onIce);
|
|
182
|
+
this.ws.on('vision_status', onStatus);
|
|
183
|
+
this.wsHandlers = [
|
|
184
|
+
{ event: 'vision_answer', handler: onAnswer },
|
|
185
|
+
{ event: 'vision_ice', handler: onIce },
|
|
186
|
+
{ event: 'vision_status', handler: onStatus },
|
|
187
|
+
];
|
|
188
|
+
// Mirror the KVS-mode stop-race guards: if stop() is called while
|
|
189
|
+
// createOffer/setLocalDescription are in flight (rapid React HMR,
|
|
190
|
+
// unmount+remount in dev, or a fast vision-toggle cycle), the
|
|
191
|
+
// awaits continue against a closed PC and throw InvalidStateError.
|
|
192
|
+
// The guards short-circuit cleanly instead.
|
|
193
|
+
const offer = await pc.createOffer();
|
|
194
|
+
if (this.stopped)
|
|
195
|
+
return;
|
|
196
|
+
await pc.setLocalDescription(offer);
|
|
197
|
+
if (this.stopped)
|
|
198
|
+
return;
|
|
199
|
+
this.ws.sendVisionOffer({
|
|
200
|
+
action: 'vision_offer',
|
|
201
|
+
sdp: offer.sdp ?? '',
|
|
202
|
+
fps: this.fps,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* KVS-mode signaling: SDP offer/answer + ICE trickle flow through
|
|
207
|
+
* an Amazon KVS WebRTC signaling channel. The SDK is dynamically
|
|
208
|
+
* imported so local-only builds (which never set `credentials.mode
|
|
209
|
+
* === 'kvs'`) don't pay the bundle cost.
|
|
210
|
+
*
|
|
211
|
+
* The signed wss:// URL the backend mints is what the SDK opens —
|
|
212
|
+
* raw AWS credentials never reach the browser. ICE servers in
|
|
213
|
+
* `credentials.iceServers` include the KVS-managed STUN entry plus
|
|
214
|
+
* any short-term TURN entries (`expiresIn` seconds). Callers must
|
|
215
|
+
* re-fetch credentials before that elapses if a session outlives
|
|
216
|
+
* the TTL; this publisher does not auto-refresh.
|
|
217
|
+
*
|
|
218
|
+
* **Async timing note:** the SDP offer is NOT sent inline with
|
|
219
|
+
* `start()`. The KVS SignalingClient uses an EventEmitter pattern —
|
|
220
|
+
* we subscribe to its `open` event and send the offer from inside
|
|
221
|
+
* that handler. So `start()` returns to the caller before the offer
|
|
222
|
+
* has been created or sent (an event loop tick or two later). Code
|
|
223
|
+
* that calls `start()` and synchronously checks `pc.signalingState`
|
|
224
|
+
* will see `"stable"` (no offer yet). This is observable but
|
|
225
|
+
* intentional — chat turns fired in the window between `start()`
|
|
226
|
+
* and `open` correctly resolve to "no vision frame this turn" via
|
|
227
|
+
* `session.kvs_client_id === None` server-side.
|
|
228
|
+
*/
|
|
229
|
+
async startKvsMode() {
|
|
230
|
+
if (!this.credentials || this.credentials.mode !== 'kvs') {
|
|
231
|
+
throw new Error('VisionPublisher.startKvsMode called without kvs credentials');
|
|
232
|
+
}
|
|
233
|
+
if (!this.credentials.signedSignalingUrl) {
|
|
234
|
+
throw new Error('VisionPublisher: kvs mode credentials missing signedSignalingUrl');
|
|
235
|
+
}
|
|
236
|
+
if (!this.credentials.channelArn || !this.credentials.clientId) {
|
|
237
|
+
throw new Error('VisionPublisher: kvs mode credentials missing channelArn/clientId');
|
|
238
|
+
}
|
|
239
|
+
// Dynamic import keeps the SDK out of the local-mode bundle. Errors
|
|
240
|
+
// here usually mean the optional peer dep is uninstalled; surface
|
|
241
|
+
// them clearly so deploy misconfigurations are obvious.
|
|
242
|
+
let sdkModule;
|
|
243
|
+
try {
|
|
244
|
+
sdkModule = await import(
|
|
245
|
+
// Keep the literal specifier so the bundler can statically
|
|
246
|
+
// discover the chunk. Resolution is layered:
|
|
247
|
+
// - Bundler (Turbopack): resolved via the host app's
|
|
248
|
+
// `turbopack.resolveAlias` entry, which anchors the lookup
|
|
249
|
+
// at the web project (web/node_modules) — needed because
|
|
250
|
+
// client-core is transpiled from source and its realpath
|
|
251
|
+
// (packages/client-core) can't see web/node_modules.
|
|
252
|
+
// - Type-checker (tsc): the host's web-rooted install does not
|
|
253
|
+
// place the SDK on client-core's realpath, so tsc can't find
|
|
254
|
+
// the types here; @ts-ignore suppresses that. (The SDK is an
|
|
255
|
+
// optional peer; it may also be genuinely absent at RUNTIME
|
|
256
|
+
// for a published consumer that didn't install it — handled
|
|
257
|
+
// by the surrounding try/catch.)
|
|
258
|
+
// Result is treated as ``unknown`` and narrowed below.
|
|
259
|
+
/* webpackChunkName: "kvs-webrtc" */
|
|
260
|
+
// @ts-ignore — optional peer dep; types/module may be unresolvable
|
|
261
|
+
// from client-core's realpath in a host's web-rooted install
|
|
262
|
+
'amazon-kinesis-video-streams-webrtc');
|
|
263
|
+
}
|
|
264
|
+
catch (err) {
|
|
265
|
+
this.emitError(new Error('VisionPublisher: failed to load amazon-kinesis-video-streams-webrtc; ' +
|
|
266
|
+
'install it as a peer dep to enable kvs signaling mode'));
|
|
267
|
+
// Don't re-throw: callers that float the start() promise (the
|
|
268
|
+
// React hook does this) would get an unhandled rejection on top
|
|
269
|
+
// of the error event we just emitted. The onError channel is
|
|
270
|
+
// the contract; the throw would be a redundant second signal.
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
const KvsCtors = sdkModule;
|
|
274
|
+
const pc = new RTCPeerConnection({ iceServers: this.iceServers });
|
|
275
|
+
this.pc = pc;
|
|
276
|
+
pc.addEventListener('connectionstatechange', () => {
|
|
277
|
+
if (!this.pc)
|
|
278
|
+
return;
|
|
279
|
+
if (this.pc.connectionState === 'failed' && !this.stopped) {
|
|
280
|
+
this.emitError(new Error('VisionPublisher peer connection failed (kvs)'));
|
|
281
|
+
this.stop();
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
pc.addTrack(this.track);
|
|
285
|
+
// The backend mints a fully SigV4-presigned wss:// URL — it bakes in
|
|
286
|
+
// X-Amz-ChannelARN, X-Amz-ClientId, and the signature
|
|
287
|
+
// (shared/kvs_webrtc._sign_wss_url). Supply a no-op requestSigner that
|
|
288
|
+
// returns that URL verbatim. Without a requestSigner the SDK builds a
|
|
289
|
+
// SigV4 signer from `config.credentials` and throws "credentials
|
|
290
|
+
// cannot be undefined" — and providing real credentials would mean
|
|
291
|
+
// shipping AWS keys to the browser, exactly what the presigned-URL
|
|
292
|
+
// design exists to avoid. getSignedURL is the ONLY place the SDK
|
|
293
|
+
// signs; follow-up SDP/ICE messages ride the already-authenticated
|
|
294
|
+
// WebSocket unsigned, so the no-op signer fully covers the contract.
|
|
295
|
+
const presignedUrl = this.credentials.signedSignalingUrl;
|
|
296
|
+
const signaling = new KvsCtors.SignalingClient({
|
|
297
|
+
channelARN: this.credentials.channelArn,
|
|
298
|
+
channelEndpoint: this.credentials.signedSignalingUrl,
|
|
299
|
+
clientId: this.credentials.clientId,
|
|
300
|
+
role: KvsCtors.Role.VIEWER,
|
|
301
|
+
// Region is stored by the SDK but not used for signing here (we
|
|
302
|
+
// bypass its signer); kept consistent with the channel's region.
|
|
303
|
+
region: this.credentials.region ?? 'us-east-1',
|
|
304
|
+
systemClockOffset: 0,
|
|
305
|
+
requestSigner: {
|
|
306
|
+
getSignedURL: async () => presignedUrl,
|
|
307
|
+
},
|
|
308
|
+
});
|
|
309
|
+
this.kvsSignalingClient = signaling;
|
|
310
|
+
pc.addEventListener('icecandidate', (ev) => {
|
|
311
|
+
const candidate = ev.candidate;
|
|
312
|
+
if (!candidate)
|
|
313
|
+
return; // end-of-candidates
|
|
314
|
+
signaling.sendIceCandidate({
|
|
315
|
+
candidate: candidate.candidate,
|
|
316
|
+
sdpMid: candidate.sdpMid ?? undefined,
|
|
317
|
+
sdpMLineIndex: candidate.sdpMLineIndex ?? undefined,
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
// Track whether we've notified the chat-WS of our ClientId so
|
|
321
|
+
// stop() knows whether to send detach.
|
|
322
|
+
//
|
|
323
|
+
// The `vision_attach` send waits for KVS's `open` event (rather
|
|
324
|
+
// than firing immediately at start()) because we want to send
|
|
325
|
+
// ClientId only after the signaling channel is actually live —
|
|
326
|
+
// otherwise a chat turn fired in the window between start() and
|
|
327
|
+
// open might race against a still-empty session. The window is
|
|
328
|
+
// sub-second in practice; a chat turn during that window correctly
|
|
329
|
+
// resolves to "no vision frame yet" (the dispatcher reads
|
|
330
|
+
// session.kvs_client_id = None) and the user just gets a frameless
|
|
331
|
+
// answer for that one turn. The next turn picks up the buffer.
|
|
332
|
+
const clientId = this.credentials.clientId;
|
|
333
|
+
signaling.on('open', async () => {
|
|
334
|
+
// Stop-race guard: if stop() was called between `start()` and
|
|
335
|
+
// this handler firing, the local peer is already closed and
|
|
336
|
+
// sending vision_attach would leave the server with a kvs_client_id
|
|
337
|
+
// binding but no receiver. Bail before any state-mutating call.
|
|
338
|
+
if (this.stopped)
|
|
339
|
+
return;
|
|
340
|
+
try {
|
|
341
|
+
// Tell the chat-WS our KVS ClientId BEFORE the offer is sent
|
|
342
|
+
// — the backend dispatcher needs the ClientId on session state
|
|
343
|
+
// by the time the first chat turn looks up the FrameBuffer.
|
|
344
|
+
// Skipping this is the bug that left KVS-mode silently broken
|
|
345
|
+
// (router had the buffer; chat-WS session didn't know about it).
|
|
346
|
+
this.ws.sendVisionAttach({ action: 'vision_attach', clientId });
|
|
347
|
+
const offer = await pc.createOffer();
|
|
348
|
+
if (this.stopped)
|
|
349
|
+
return;
|
|
350
|
+
await pc.setLocalDescription(offer);
|
|
351
|
+
if (this.stopped)
|
|
352
|
+
return;
|
|
353
|
+
signaling.sendSdpOffer({ type: 'offer', sdp: offer.sdp ?? '' });
|
|
354
|
+
}
|
|
355
|
+
catch (err) {
|
|
356
|
+
this.emitError(err instanceof Error ? err : new Error(String(err)));
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
signaling.on('sdpAnswer', async (answer) => {
|
|
360
|
+
try {
|
|
361
|
+
await pc.setRemoteDescription(answer);
|
|
362
|
+
}
|
|
363
|
+
catch (err) {
|
|
364
|
+
// Same rationale as local-mode onAnswer: a failed remote
|
|
365
|
+
// description leaves the PC unrecoverable. Tear down so the
|
|
366
|
+
// hook can construct a fresh publisher on retry.
|
|
367
|
+
this.emitError(err instanceof Error ? err : new Error(String(err)));
|
|
368
|
+
this.stop();
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
signaling.on('iceCandidate', async (candidate) => {
|
|
372
|
+
try {
|
|
373
|
+
await pc.addIceCandidate(candidate);
|
|
374
|
+
}
|
|
375
|
+
catch (err) {
|
|
376
|
+
// ICE failures are per-candidate and survivable.
|
|
377
|
+
this.emitError(err instanceof Error ? err : new Error(String(err)));
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
signaling.on('error', (err) => {
|
|
381
|
+
this.emitError(err instanceof Error ? err : new Error(`KVS signaling: ${String(err)}`));
|
|
382
|
+
});
|
|
383
|
+
signaling.on('close', () => {
|
|
384
|
+
if (!this.stopped) {
|
|
385
|
+
this.emitError(new Error('VisionPublisher: KVS signaling closed unexpectedly'));
|
|
386
|
+
this.stop();
|
|
387
|
+
}
|
|
388
|
+
});
|
|
389
|
+
signaling.open();
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Tear down the peer connection, unsubscribe from WS events, and let
|
|
393
|
+
* the backend know via `vision_close` so it can free its receiver.
|
|
394
|
+
* Idempotent — safe to call from `finally` blocks or auto-restart
|
|
395
|
+
* paths.
|
|
396
|
+
*/
|
|
397
|
+
stop() {
|
|
398
|
+
if (this.stopped &&
|
|
399
|
+
!this.pc &&
|
|
400
|
+
this.wsHandlers.length === 0 &&
|
|
401
|
+
this.kvsSignalingClient === null) {
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
this.stopped = true;
|
|
405
|
+
if (this.pc) {
|
|
406
|
+
this.pc.close();
|
|
407
|
+
this.pc = null;
|
|
408
|
+
}
|
|
409
|
+
const wasKvs = this.kvsSignalingClient !== null;
|
|
410
|
+
if (this.kvsSignalingClient) {
|
|
411
|
+
try {
|
|
412
|
+
this.kvsSignalingClient.close();
|
|
413
|
+
}
|
|
414
|
+
catch {
|
|
415
|
+
// KVS SDK occasionally throws during close; idempotent teardown.
|
|
416
|
+
}
|
|
417
|
+
this.kvsSignalingClient = null;
|
|
418
|
+
}
|
|
419
|
+
for (const { event, handler } of this.wsHandlers) {
|
|
420
|
+
this.ws.off(event, handler);
|
|
421
|
+
}
|
|
422
|
+
this.wsHandlers = [];
|
|
423
|
+
// Local mode: vision_close frees the per-session aiortc receiver
|
|
424
|
+
// server-side. KVS mode: vision_detach releases the receiver +
|
|
425
|
+
// FrameBuffer in VisionSessionRouter keyed by ClientId.
|
|
426
|
+
// Both are fire-and-forget — the backend also cleans up on WS
|
|
427
|
+
// disconnect, so a swallow-and-return is safe.
|
|
428
|
+
try {
|
|
429
|
+
if (wasKvs) {
|
|
430
|
+
this.ws.sendVisionDetach();
|
|
431
|
+
}
|
|
432
|
+
else {
|
|
433
|
+
this.ws.sendVisionClose();
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
catch {
|
|
437
|
+
// Socket may already be closed; the backend will GC on disconnect.
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
/** Subscribe to backend `vision_status` updates (HUD telemetry). Returns
|
|
441
|
+
* an unsubscribe function so React effects can clean up. */
|
|
442
|
+
onStatus(listener) {
|
|
443
|
+
this.statusListeners.push(listener);
|
|
444
|
+
return () => {
|
|
445
|
+
this.statusListeners = this.statusListeners.filter((l) => l !== listener);
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
/** Subscribe to publisher-level errors (peer-connection failure, SDP /
|
|
449
|
+
* ICE rejection). Returns an unsubscribe function. */
|
|
450
|
+
onError(listener) {
|
|
451
|
+
this.errorListeners.push(listener);
|
|
452
|
+
return () => {
|
|
453
|
+
this.errorListeners = this.errorListeners.filter((l) => l !== listener);
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
emitError(err) {
|
|
457
|
+
for (const listener of this.errorListeners)
|
|
458
|
+
listener(err);
|
|
459
|
+
}
|
|
460
|
+
static resolveTrack(input) {
|
|
461
|
+
// jsdom < 25 doesn't ship MediaStream, so guard the `instanceof`
|
|
462
|
+
// check on a truthy global. When the global isn't installed we
|
|
463
|
+
// assume the caller passed a track directly.
|
|
464
|
+
const MediaStreamCtor = globalThis.MediaStream;
|
|
465
|
+
if (MediaStreamCtor && input instanceof MediaStreamCtor) {
|
|
466
|
+
const track = input.getVideoTracks()[0];
|
|
467
|
+
if (!track) {
|
|
468
|
+
throw new Error('VisionPublisher: MediaStream has no video tracks');
|
|
469
|
+
}
|
|
470
|
+
return track;
|
|
471
|
+
}
|
|
472
|
+
return input;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
//# sourceMappingURL=VisionPublisher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VisionPublisher.js","sourceRoot":"","sources":["../../src/vision/VisionPublisher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AA+CH,MAAM,WAAW,GAAG,GAAG,CAAC;AAExB,MAAM,OAAO,eAAe;IACT,EAAE,CAAgB;IAClB,KAAK,CAAmB;IACxB,GAAG,CAAS;IACZ,UAAU,CAAiB;IAC3B,WAAW,CAA8B;IAClD,EAAE,GAA6B,IAAI,CAAC;IACpC,kBAAkB,GAAkC,IAAI,CAAC;IACzD,eAAe,GAA2B,EAAE,CAAC;IAC7C,cAAc,GAA0B,EAAE,CAAC;IAC3C,UAAU,GAAgE,EAAE,CAAC;IAC7E,OAAO,GAAG,KAAK,CAAC;IAExB,YAAY,IAA4B;QACtC,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;QAClB,IAAI,CAAC,KAAK,GAAG,eAAe,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACtD,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,WAAW,CAAC;QAC3C,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC;QAC5C,+DAA+D;QAC/D,+DAA+D;QAC/D,mCAAmC;QACnC,IAAI,CAAC,UAAU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|
3
|
+
*
|
|
4
|
+
* The chat-API returns `ChatVisionRtcCredentialsResponse` whose ICE-server
|
|
5
|
+
* entries use `string | null` for optional fields (JSON can't carry
|
|
6
|
+
* `undefined`). `RTCIceServer` / `VisionRtcCredentials` want `string |
|
|
7
|
+
* undefined` instead, so we normalise here.
|
|
8
|
+
*
|
|
9
|
+
* `traceId` is a log-correlation field on the response; it is NOT part of
|
|
10
|
+
* `VisionRtcCredentials` and is intentionally dropped.
|
|
11
|
+
*/
|
|
12
|
+
import type { ChatVisionRtcCredentialsResponse } from '../api';
|
|
13
|
+
import type { VisionRtcCredentials } from './types';
|
|
14
|
+
/**
|
|
15
|
+
* Convert a `ChatVisionRtcCredentialsResponse` (API wire shape) into the
|
|
16
|
+
* `VisionRtcCredentials` expected by `VisionPublisher`.
|
|
17
|
+
*
|
|
18
|
+
* - `null` ICE `username` / `credential` fields are coerced to `undefined`.
|
|
19
|
+
* - `traceId` (present on the response for log correlation) is dropped.
|
|
20
|
+
*/
|
|
21
|
+
export declare function toVisionRtcCredentials(response: ChatVisionRtcCredentialsResponse): VisionRtcCredentials;
|
|
22
|
+
//# sourceMappingURL=credentials.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../../src/vision/credentials.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,QAAQ,CAAC;AAC/D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAEpD;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,gCAAgC,GACzC,oBAAoB,CActB"}
|