@escapeaihq/client-core 0.49.0 → 0.52.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 +4 -4
- package/dist/adapters/worldAdapter.js +1 -1
- package/dist/conversation/binding.d.ts +28 -1
- package/dist/conversation/binding.d.ts.map +1 -1
- package/dist/conversation/binding.js +12 -0
- package/dist/conversation/binding.js.map +1 -1
- package/dist/conversation/controller.d.ts +16 -0
- package/dist/conversation/controller.d.ts.map +1 -1
- package/dist/conversation/controller.js +22 -0
- package/dist/conversation/controller.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -4
- package/dist/index.js.map +1 -1
- package/dist/reactor/dmSceneControlPrompt.d.ts +40 -0
- package/dist/reactor/dmSceneControlPrompt.d.ts.map +1 -0
- package/dist/reactor/dmSceneControlPrompt.js +83 -0
- package/dist/reactor/dmSceneControlPrompt.js.map +1 -0
- package/dist/reactor/index.d.ts +1 -0
- package/dist/reactor/index.d.ts.map +1 -1
- package/dist/reactor/index.js +3 -0
- package/dist/reactor/index.js.map +1 -1
- package/dist/reactor/promptAddonRegistry.js +2 -2
- package/dist/reactor/promptAddonRegistry.js.map +1 -1
- package/dist/reactor/toolPromptAddon.d.ts +37 -28
- package/dist/reactor/toolPromptAddon.d.ts.map +1 -1
- package/dist/reactor/toolPromptAddon.js +48 -100
- package/dist/reactor/toolPromptAddon.js.map +1 -1
- package/dist/websocket.d.ts +119 -2
- package/dist/websocket.d.ts.map +1 -1
- package/dist/websocket.js +73 -0
- package/dist/websocket.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/conversation/binding.test.ts +53 -0
- package/src/__tests__/conversation/controller.test.ts +117 -0
- package/src/__tests__/reactor/promptAddonRegistry.test.ts +3 -1
- package/src/__tests__/reactor/toolPromptAddon.test.ts +34 -42
- package/src/__tests__/websocket-session-attach.test.ts +288 -0
- package/src/conversation/binding.ts +40 -1
- package/src/conversation/controller.ts +39 -0
- package/src/index.ts +10 -4
- package/src/reactor/dmSceneControlPrompt.ts +85 -0
- package/src/reactor/index.ts +3 -0
- package/src/reactor/promptAddonRegistry.ts +2 -2
- package/src/reactor/toolPromptAddon.ts +51 -101
- package/src/websocket.ts +186 -2
package/src/websocket.ts
CHANGED
|
@@ -86,6 +86,30 @@ export interface PlaybackState {
|
|
|
86
86
|
paused: boolean;
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
+
/**
|
|
90
|
+
* The anchored playback state replayed in a `session_attached` ack (B5,
|
|
91
|
+
* Dashboard Redesign §10). Read server-side from the EXISTING
|
|
92
|
+
* `PlaybackStateStore` row (`(userId, videoId)`) and replayed verbatim to a
|
|
93
|
+
* newly-attaching connection so a chat opened on one device picks up where
|
|
94
|
+
* another device left the playhead (cross-device hand-off, owner decision D6).
|
|
95
|
+
*
|
|
96
|
+
* Camel-case mirrors the dict `api/chat/ws.py::_handle_session_attach` builds
|
|
97
|
+
* (`anchoredState`): `current_time → currentTime`, `experience_source →
|
|
98
|
+
* experienceSource`, etc. Omitted from the ack entirely when the store has no
|
|
99
|
+
* fresh row yet — the attach is still confirmed, the field is just `undefined`.
|
|
100
|
+
*/
|
|
101
|
+
export interface SessionAnchoredState {
|
|
102
|
+
currentTime: number;
|
|
103
|
+
/** `null` on the wire when the last publish carried no shot id. */
|
|
104
|
+
shotId?: string | null;
|
|
105
|
+
paused: boolean;
|
|
106
|
+
/** The active experience source (`video` / `world` / `generated`); `null`
|
|
107
|
+
* for a legacy frame published before A10 added the field. */
|
|
108
|
+
experienceSource?: string | null;
|
|
109
|
+
/** Server epoch-seconds the row was last written. */
|
|
110
|
+
updatedAt?: number;
|
|
111
|
+
}
|
|
112
|
+
|
|
89
113
|
export type ChatWsEvent =
|
|
90
114
|
| { type: 'token'; timestamp?: number; content: string; personaId?: string }
|
|
91
115
|
| {
|
|
@@ -210,6 +234,47 @@ export type ChatWsEvent =
|
|
|
210
234
|
| 'seek_video'
|
|
211
235
|
| 'set_experience_source';
|
|
212
236
|
params: Record<string, unknown>;
|
|
237
|
+
}
|
|
238
|
+
| {
|
|
239
|
+
/**
|
|
240
|
+
* Dashboard Spec B (§10 / B5) — acknowledgement that this connection
|
|
241
|
+
* joined a SERVER-ANCHORED chat session (it sent `session_attach`).
|
|
242
|
+
* Emitted by `api/chat/ws.py::_handle_session_attach` (wire type
|
|
243
|
+
* `"session_attached"`, single-sourced in
|
|
244
|
+
* `SESSION_ATTACHED_EVENT_TYPE`). Carries the OTHER connection ids
|
|
245
|
+
* already present on the anchor (`peers`) and — when the existing
|
|
246
|
+
* `PlaybackStateStore` had a fresh row — the `anchoredState` the other
|
|
247
|
+
* device left behind (the cross-device hand-off playhead). Added as a
|
|
248
|
+
* union variant so exhaustive consumers get a typed arm; no live
|
|
249
|
+
* consumer is wired until the floater handles it. Land-dark: a client
|
|
250
|
+
* that never sends `session_attach` never receives this.
|
|
251
|
+
*/
|
|
252
|
+
type: 'session_attached';
|
|
253
|
+
timestamp?: number;
|
|
254
|
+
videoId: string;
|
|
255
|
+
connectionId: string;
|
|
256
|
+
peers: string[];
|
|
257
|
+
anchoredState?: SessionAnchoredState;
|
|
258
|
+
}
|
|
259
|
+
| {
|
|
260
|
+
/**
|
|
261
|
+
* Dashboard Spec B (§10 / B5) — presence fan-out: another tab/device
|
|
262
|
+
* just `attached` to (or `detached` from) the SAME server-anchored
|
|
263
|
+
* session. Emitted by `_handle_session_attach` / `_detach_session`
|
|
264
|
+
* (wire type `"presence"`, `event` ∈ {`attached`,`detached`} —
|
|
265
|
+
* single-sourced in `PRESENCE_EVENT_TYPE` / `PRESENCE_ATTACHED` /
|
|
266
|
+
* `PRESENCE_DETACHED`). The originator is excluded from its own
|
|
267
|
+
* `attached` fan-out (it learns the peer list from the ack instead).
|
|
268
|
+
* `videoId` is present on `attached`, omitted on `detached` (the
|
|
269
|
+
* survivor already knows the anchor). Added as a union variant so the
|
|
270
|
+
* floater can render a lightweight presence indicator; absence of peers
|
|
271
|
+
* means it never fires (byte-identical to a no-peer floater).
|
|
272
|
+
*/
|
|
273
|
+
type: 'presence';
|
|
274
|
+
timestamp?: number;
|
|
275
|
+
event: 'attached' | 'detached';
|
|
276
|
+
connectionId: string;
|
|
277
|
+
videoId?: string;
|
|
213
278
|
};
|
|
214
279
|
|
|
215
280
|
/**
|
|
@@ -292,7 +357,15 @@ export type BinaryHandler = (data: ArrayBuffer) => void;
|
|
|
292
357
|
*
|
|
293
358
|
* Spec: `specs/2026-05-22-phase-2-multimodal-watch.md`.
|
|
294
359
|
*/
|
|
295
|
-
export type ChatWsTypedEvent =
|
|
360
|
+
export type ChatWsTypedEvent =
|
|
361
|
+
| 'vision_answer'
|
|
362
|
+
| 'vision_ice'
|
|
363
|
+
| 'vision_status'
|
|
364
|
+
// Dashboard Spec B (§10 / B5) — server-anchored session presence. These ride
|
|
365
|
+
// the SAME typed-event dispatcher as the vision-signaling events (one
|
|
366
|
+
// dispatcher, not a parallel one) keyed by their inbound `type` discriminator.
|
|
367
|
+
| 'session_attached'
|
|
368
|
+
| 'presence';
|
|
296
369
|
|
|
297
370
|
/** Inbound `vision_answer` payload from the backend after it processes
|
|
298
371
|
* the publisher's offer. */
|
|
@@ -321,6 +394,31 @@ export interface VisionStatusEvent {
|
|
|
321
394
|
processingPaused: boolean;
|
|
322
395
|
}
|
|
323
396
|
|
|
397
|
+
/**
|
|
398
|
+
* Inbound `session_attached` ack payload (B5). Mirrors the
|
|
399
|
+
* {@link ChatWsEvent} `session_attached` variant — the SAME shape the server
|
|
400
|
+
* sends (camel-case on the wire already), surfaced to typed `on()` listeners
|
|
401
|
+
* so the floater can replay the anchored playhead + seed the peer list.
|
|
402
|
+
*/
|
|
403
|
+
export interface SessionAttachedEvent {
|
|
404
|
+
type: 'session_attached';
|
|
405
|
+
videoId: string;
|
|
406
|
+
connectionId: string;
|
|
407
|
+
peers: string[];
|
|
408
|
+
anchoredState?: SessionAnchoredState;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Inbound `presence` payload (B5) — a peer tab/device `attached`/`detached`.
|
|
413
|
+
* Mirrors the {@link ChatWsEvent} `presence` variant; camel-case on the wire.
|
|
414
|
+
*/
|
|
415
|
+
export interface PresenceEvent {
|
|
416
|
+
type: 'presence';
|
|
417
|
+
event: 'attached' | 'detached';
|
|
418
|
+
connectionId: string;
|
|
419
|
+
videoId?: string;
|
|
420
|
+
}
|
|
421
|
+
|
|
324
422
|
export type ChatWsTypedEventPayload<E extends ChatWsTypedEvent> =
|
|
325
423
|
E extends 'vision_answer'
|
|
326
424
|
? VisionAnswerEvent
|
|
@@ -328,7 +426,11 @@ export type ChatWsTypedEventPayload<E extends ChatWsTypedEvent> =
|
|
|
328
426
|
? VisionIceEvent
|
|
329
427
|
: E extends 'vision_status'
|
|
330
428
|
? VisionStatusEvent
|
|
331
|
-
:
|
|
429
|
+
: E extends 'session_attached'
|
|
430
|
+
? SessionAttachedEvent
|
|
431
|
+
: E extends 'presence'
|
|
432
|
+
? PresenceEvent
|
|
433
|
+
: never;
|
|
332
434
|
|
|
333
435
|
export type TypedEventHandler<E extends ChatWsTypedEvent = ChatWsTypedEvent> = (
|
|
334
436
|
payload: ChatWsTypedEventPayload<E>,
|
|
@@ -744,6 +846,48 @@ export class ChatWebSocket {
|
|
|
744
846
|
this._sendVisionJson({ action: 'vision_detach' });
|
|
745
847
|
}
|
|
746
848
|
|
|
849
|
+
/**
|
|
850
|
+
* Attach this connection to a SERVER-ANCHORED chat session (B5, Dashboard
|
|
851
|
+
* Redesign §10). The anchor is the `(userId, videoId)` pair — the same key
|
|
852
|
+
* the cross-device `PlaybackStateStore` row uses — so the server can replay
|
|
853
|
+
* the playhead another device left (a `session_attached` ack) and fan
|
|
854
|
+
* `presence` events between the user's tabs/devices (owner decision D6).
|
|
855
|
+
*
|
|
856
|
+
* Wire shape EXACTLY matches `shared/websocket_models.py::SessionAttachMessage`
|
|
857
|
+
* (`{ action, videoId, connectionId }`, `extra="forbid"`). `connectionId` is
|
|
858
|
+
* an opaque per-tab/device label the caller mints (the server treats it only
|
|
859
|
+
* as a fan-out name, never for auth — the row is scoped to the authenticated
|
|
860
|
+
* user). Fire-and-forget like the vision sends: best-effort, drops silently
|
|
861
|
+
* when the socket isn't OPEN (the server reconciles on the next attach /
|
|
862
|
+
* disconnect). Land-dark: a client that never calls this is byte-identical.
|
|
863
|
+
*/
|
|
864
|
+
sendSessionAttach(payload: {
|
|
865
|
+
action: 'session_attach';
|
|
866
|
+
videoId: string;
|
|
867
|
+
connectionId: string;
|
|
868
|
+
}): void {
|
|
869
|
+
this._sendVisionJson({
|
|
870
|
+
action: payload.action,
|
|
871
|
+
videoId: payload.videoId,
|
|
872
|
+
connectionId: payload.connectionId,
|
|
873
|
+
});
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
/**
|
|
877
|
+
* Leave the server-anchored session WITHOUT closing the socket (B5). Needed
|
|
878
|
+
* when a LONG-LIVED ADOPTED socket (the Watch surface's shared socket) rebinds
|
|
879
|
+
* away from its video session — e.g. the floater switches from a video
|
|
880
|
+
* conversation to a persona one — so the connection doesn't stay registered
|
|
881
|
+
* under the old `(user, video)` anchor (a stale peer for the user's other
|
|
882
|
+
* tabs). The backend (`api/chat/ws.py` `session_detach` action) fans a
|
|
883
|
+
* `detached` presence to the survivors + clears its per-connection holder.
|
|
884
|
+
* Fire-and-forget like the other session/vision sends; the backend also
|
|
885
|
+
* detaches on socket close, so a dropped detach is harmless.
|
|
886
|
+
*/
|
|
887
|
+
sendSessionDetach(): void {
|
|
888
|
+
this._sendVisionJson({ action: 'session_detach' });
|
|
889
|
+
}
|
|
890
|
+
|
|
747
891
|
/**
|
|
748
892
|
* Register a typed listener for a vision-signaling event. Returns
|
|
749
893
|
* void (matches the `messageHandlers` pattern); unsubscribe via
|
|
@@ -785,6 +929,46 @@ export class ChatWebSocket {
|
|
|
785
929
|
private _dispatchVisionEvent(raw: Record<string, unknown>): void {
|
|
786
930
|
const t = raw['type'] as string | undefined;
|
|
787
931
|
const action = raw['action'] as string | undefined;
|
|
932
|
+
// B5 — server-anchored session presence. These inbound events are already
|
|
933
|
+
// camel-case on the wire (the server builds the dict in camelCase), so we
|
|
934
|
+
// pass the fields through to typed listeners after a defensive coerce. The
|
|
935
|
+
// raw event ALSO flows on through `messageHandlers` as a `WebSocketMessage`
|
|
936
|
+
// (the caller in `onmessage`), so a `ChatWsEvent`-switch consumer can read
|
|
937
|
+
// the same frame too — same back-compat contract the vision events keep.
|
|
938
|
+
if (t === 'session_attached') {
|
|
939
|
+
const anchored = raw['anchoredState'] as
|
|
940
|
+
| Record<string, unknown>
|
|
941
|
+
| undefined;
|
|
942
|
+
const payload: SessionAttachedEvent = {
|
|
943
|
+
type: 'session_attached',
|
|
944
|
+
videoId: String(raw['videoId'] ?? ''),
|
|
945
|
+
connectionId: String(raw['connectionId'] ?? ''),
|
|
946
|
+
peers: Array.isArray(raw['peers']) ? (raw['peers'] as string[]) : [],
|
|
947
|
+
};
|
|
948
|
+
if (anchored) {
|
|
949
|
+
payload.anchoredState = {
|
|
950
|
+
currentTime: Number(anchored['currentTime'] ?? 0),
|
|
951
|
+
shotId: (anchored['shotId'] as string | null | undefined) ?? null,
|
|
952
|
+
paused: Boolean(anchored['paused']),
|
|
953
|
+
experienceSource:
|
|
954
|
+
(anchored['experienceSource'] as string | null | undefined) ?? null,
|
|
955
|
+
updatedAt: anchored['updatedAt'] as number | undefined,
|
|
956
|
+
};
|
|
957
|
+
}
|
|
958
|
+
this._fireTyped('session_attached', payload);
|
|
959
|
+
return;
|
|
960
|
+
}
|
|
961
|
+
if (t === 'presence') {
|
|
962
|
+
this._fireTyped('presence', {
|
|
963
|
+
type: 'presence',
|
|
964
|
+
event: raw['event'] === 'detached' ? 'detached' : 'attached',
|
|
965
|
+
connectionId: String(raw['connectionId'] ?? ''),
|
|
966
|
+
...(raw['videoId'] !== undefined
|
|
967
|
+
? { videoId: String(raw['videoId']) }
|
|
968
|
+
: {}),
|
|
969
|
+
});
|
|
970
|
+
return;
|
|
971
|
+
}
|
|
788
972
|
if (t === 'vision_answer') {
|
|
789
973
|
this._fireTyped('vision_answer', {
|
|
790
974
|
type: 'vision_answer',
|