@touchcastllc/napster-companion-api-dev 2.1.0-alpha.5 → 2.1.0-alpha.7

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.
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Live captions for the avatar's speech (CA-1147, WCAG 1.2.4), paced by a
3
+ * clock — because nothing on the data channel says when a word is spoken.
4
+ *
5
+ * Measured live (2026-10-26, playground probe): the whole reply arrives as
6
+ * `message_received` deltas within ~1.3 s of `talk_state_changed: started`
7
+ * (generation speed, ~190 tokens/s), while the avatar then speaks it for
8
+ * 30 s or more. `talk_state_changed` carries no text, and its
9
+ * `sentence_index` counts audio chunks that match no text split (a greeting
10
+ * the browser splits into 4 sentences reached index 5). The backend cannot
11
+ * add the text: the model's API gives no text with timestamps.
12
+ *
13
+ * So the reply is cut into a-few-words chunks (`cutChunk`) and each chunk
14
+ * stays on screen for its length divided by a speaking rate in chars/s.
15
+ * The rate starts at CAPTION_RATE_START and is recalibrated from every
16
+ * finished reply (`started` → `ended`: chars / seconds, averaged with the
17
+ * rate in use so one odd reply cannot throw it). `ended` plays whatever is
18
+ * still unread faster and lingers on the last chunk; `canceled` (the user
19
+ * interrupted) hides at once. The error on a long reply is a second or two
20
+ * either way, which is within what live captions on TV lag by.
21
+ *
22
+ * No DOM here: the pacer reports through `onChunk(text | null)` and the
23
+ * Avatar puts that in the store (`avatar.caption`), where the caption strip
24
+ * and its PiP mirror read it.
25
+ */
26
+ /** Longest chunk, in chars — "a few words", one or two short lines. */
27
+ export declare const CAPTION_MAX_CHARS = 42;
28
+ /** Don't cut at a clause mark or a space before this many chars. */
29
+ export declare const CAPTION_MIN_CUT = 14;
30
+ /** Shortest time a chunk stays on screen. */
31
+ export declare const CAPTION_MIN_MS = 700;
32
+ /** How long the last chunk stays after the avatar has stopped. */
33
+ export declare const CAPTION_LINGER_MS = 1500;
34
+ /** Speed-up for chunks still unread when `ended` arrives. */
35
+ export declare const CAPTION_CATCH_UP = 2.5;
36
+ /** Speaking rate the clock starts with, chars per second. */
37
+ export declare const CAPTION_RATE_START = 18;
38
+ export declare const CAPTION_RATE_MIN = 8;
39
+ export declare const CAPTION_RATE_MAX = 30;
40
+ /**
41
+ * The next caption chunk off the unread text, or `null` to wait for more
42
+ * deltas. Cuts after the last sentence end in the window, else after the
43
+ * last clause mark, else at the last word boundary, else hard at the limit.
44
+ * A short tail is taken whole only when the reply is complete or the tail
45
+ * ends a sentence — otherwise the chunk would end mid-phrase and the words
46
+ * still streaming would come as a stray fragment.
47
+ */
48
+ export declare function cutChunk(rest: string, complete: boolean): string | null;
49
+ /** Collapses whitespace and trims a cut chunk. */
50
+ export declare function cleanChunk(chunk: string): string;
51
+ /**
52
+ * The words the avatar speaks, from the reply text as it arrives (CA-1147).
53
+ * Agents answer in markdown when asked to — found live: `- ` lists,
54
+ * `**bold**`, `# headings`, `[text](url)` links — and the avatar speaks only
55
+ * the words, so the caption shows only them: markers and emphasis go, a
56
+ * link keeps its text, and each line becomes a sentence ("Mango. Pear.
57
+ * Strawberry"), which also gives the cutter its cut points.
58
+ *
59
+ * While the text is still streaming (`complete` false), anything that may
60
+ * yet turn into markup — a half-sent link, a line that so far is only "-"
61
+ * or "1", a "_" that may become "__" — is held back. That keeps the result
62
+ * of every streamed prefix a prefix of the final result, which the pacer
63
+ * relies on: it counts how much of THIS text it has shown.
64
+ */
65
+ export declare function cleanCaptionText(raw: string, complete: boolean): string;
66
+ /**
67
+ * Where to go on in `text` after `shown` — the chunk on screen — when the
68
+ * text changed under the part already shown (CA-1147). Never seen live:
69
+ * `completed` matched the joined deltas in 20 of 20 replies. Should it not,
70
+ * the old count of shown characters (`offset`) would land mid-word in the
71
+ * new text. Finds the longest tail of `shown` (whole words, 4+ chars) in
72
+ * `text`, the occurrence ending nearest `offset`, and goes on after it;
73
+ * failing that, moves `offset` on to the end of the word it falls in.
74
+ */
75
+ export declare function realignOffset(text: string, offset: number, shown: string): number;
76
+ export interface CaptionPacer {
77
+ /** A `message_received` delta of the assistant's reply `itemId`. */
78
+ delta(itemId: string, content: string): void;
79
+ /** The `completed` message: the whole reply text, replacing the deltas. */
80
+ completed(itemId: string, content: string): void;
81
+ /**
82
+ * A `created` message with text: a puppeteer line, or one sentence of it
83
+ * when the line is split (CA-1274). No delta or `completed` follows.
84
+ */
85
+ created(itemId: string, content: string): void;
86
+ /** A `talk_state_changed` event; `talkId` is the reply's `item_id`. */
87
+ talk(state: string | undefined, talkId: string | undefined): void;
88
+ destroy(): void;
89
+ }
90
+ /**
91
+ * One pacer per session. `onChunk` gets each chunk as it should go on
92
+ * screen and `null` when the strip should go.
93
+ */
94
+ export declare function createCaptionPacer(onChunk: (text: string | null) => void): CaptionPacer;
@@ -21,6 +21,8 @@ export declare const ANNOUNCEMENTS: {
21
21
  readonly soundUnmuted: "Sound unmuted";
22
22
  readonly screenShareStarted: "Screen sharing started";
23
23
  readonly screenShareStopped: "Screen sharing stopped";
24
+ readonly captionsOn: "Captions on";
25
+ readonly captionsOff: "Captions off";
24
26
  readonly sessionEnded: "Session ended";
25
27
  readonly connectionLost: "Connection lost. Session ended.";
26
28
  };
@@ -2,7 +2,7 @@ export { store } from "./store";
2
2
  export type { RootState } from "./store";
3
3
  export { setOnFeaturesUpdateCallback } from "./middleware/featuresUpdateMiddleware";
4
4
  export * from "./selectors";
5
- export { setSessionId, setTransport, setStopInteraction, setMuted, setMicUnavailable, setMicRecoveryOpen, setMicSourceMuted, setVolume, setAvatarSpeaking, setScreenSharing, setUserTalking, setConnectionToken, setCloseConnectionHandler, setSessionTerminatedByServer, resetAvatar, } from "./slices/avatarSlice";
5
+ export { setSessionId, setTransport, setStopInteraction, setMuted, setMicUnavailable, setMicRecoveryOpen, setMicSourceMuted, setVolume, setAvatarSpeaking, setScreenSharing, setUserTalking, setCaptionsOn, setCaption, setConnectionToken, setCloseConnectionHandler, setSessionTerminatedByServer, resetAvatar, } from "./slices/avatarSlice";
6
6
  export { setSessionStatus, resetSession } from "./slices/sessionSlice";
7
7
  export type { SessionStatus } from "./slices/sessionSlice";
8
8
  export { setFeatures, resetFeatures, setDebugMode } from "./slices/appSlice";
@@ -13,6 +13,8 @@ export declare const selectMicRecoveryOpen: (state: RootState) => boolean;
13
13
  export declare const selectMicSourceMuted: (state: RootState) => boolean;
14
14
  export declare const selectAvatarSpeaking: (state: RootState) => boolean;
15
15
  export declare const selectUserTalking: (state: RootState) => boolean;
16
+ export declare const selectCaptionsOn: (state: RootState) => boolean;
17
+ export declare const selectCaption: (state: RootState) => string | null;
16
18
  export declare const selectConnectionToken: (state: RootState) => string | undefined;
17
19
  export declare const selectStopInteraction: (state: RootState) => boolean;
18
20
  export declare const selectCloseConnectionHandler: (state: RootState) => (() => void) | undefined;
@@ -11,9 +11,11 @@ export interface AvatarState {
11
11
  avatarSpeaking: boolean;
12
12
  isScreenSharing: boolean;
13
13
  isUserTalking: boolean;
14
+ captionsOn: boolean;
15
+ caption: string | null;
14
16
  connectionToken?: string;
15
17
  closeConnectionHandler?: () => void;
16
18
  sessionTerminatedByServer: boolean;
17
19
  }
18
- export declare const setSessionId: import("@reduxjs/toolkit").ActionCreatorWithOptionalPayload<string | undefined, "avatar/setSessionId">, setTransport: import("@reduxjs/toolkit").ActionCreatorWithPayload<Transport | null, "avatar/setTransport">, setStopInteraction: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setStopInteraction">, setMuted: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setMuted">, setMicUnavailable: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setMicUnavailable">, setMicRecoveryOpen: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setMicRecoveryOpen">, setMicSourceMuted: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setMicSourceMuted">, setVolume: import("@reduxjs/toolkit").ActionCreatorWithPayload<number, "avatar/setVolume">, setAvatarSpeaking: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setAvatarSpeaking">, setScreenSharing: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setScreenSharing">, setUserTalking: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setUserTalking">, setConnectionToken: import("@reduxjs/toolkit").ActionCreatorWithOptionalPayload<string | undefined, "avatar/setConnectionToken">, setCloseConnectionHandler: import("@reduxjs/toolkit").ActionCreatorWithOptionalPayload<(() => void) | undefined, "avatar/setCloseConnectionHandler">, setSessionTerminatedByServer: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setSessionTerminatedByServer">, resetAvatar: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"avatar/resetAvatar">;
20
+ export declare const setSessionId: import("@reduxjs/toolkit").ActionCreatorWithOptionalPayload<string | undefined, "avatar/setSessionId">, setTransport: import("@reduxjs/toolkit").ActionCreatorWithPayload<Transport | null, "avatar/setTransport">, setStopInteraction: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setStopInteraction">, setMuted: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setMuted">, setMicUnavailable: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setMicUnavailable">, setMicRecoveryOpen: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setMicRecoveryOpen">, setMicSourceMuted: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setMicSourceMuted">, setVolume: import("@reduxjs/toolkit").ActionCreatorWithPayload<number, "avatar/setVolume">, setAvatarSpeaking: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setAvatarSpeaking">, setScreenSharing: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setScreenSharing">, setUserTalking: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setUserTalking">, setCaptionsOn: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setCaptionsOn">, setCaption: import("@reduxjs/toolkit").ActionCreatorWithPayload<string | null, "avatar/setCaption">, setConnectionToken: import("@reduxjs/toolkit").ActionCreatorWithOptionalPayload<string | undefined, "avatar/setConnectionToken">, setCloseConnectionHandler: import("@reduxjs/toolkit").ActionCreatorWithOptionalPayload<(() => void) | undefined, "avatar/setCloseConnectionHandler">, setSessionTerminatedByServer: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, "avatar/setSessionTerminatedByServer">, resetAvatar: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"avatar/resetAvatar">;
19
21
  export declare const avatarReducer: import("redux").Reducer<AvatarState>;
@@ -130,10 +130,14 @@ export interface EventMessage {
130
130
  event: string;
131
131
  data?: {
132
132
  state?: string;
133
+ /** `talk_state_changed`: the reply being spoken — its message's `item_id`. */
134
+ talk_id?: string;
133
135
  message?: {
134
136
  action?: string;
135
137
  content?: string;
136
138
  role?: string;
139
+ /** The reply this delta/completed message belongs to. */
140
+ item_id?: string;
137
141
  };
138
142
  /**
139
143
  * Present on `avatar_state_changed` events for a deferred-video session
@@ -212,6 +216,13 @@ export interface FeatureConfig {
212
216
  screenShare?: {
213
217
  enabled: boolean;
214
218
  };
219
+ /** Live captions of the avatar's speech (WCAG 1.2.4 Captions (Live)). The
220
+ * control bar gets a captions button; captions stay hidden until the user
221
+ * turns them on there. The text is the avatar's own, in the language it
222
+ * speaks. Defaults to `enabled: false`. */
223
+ captions?: {
224
+ enabled: boolean;
225
+ };
215
226
  /** Built-in controls block (mute/volume/screen-share/end buttons) rendered over
216
227
  * the avatar. Disable when the embedding app provides its own UI for these
217
228
  * actions (e.g. via `muteMic`/`unmuteMic`, `stopAvatarTalking`, etc.).
@@ -80,6 +80,11 @@ export declare class InactiveOverlayManager {
80
80
  * keeps running since the same DOM node (and its timer) is preserved.
81
81
  */
82
82
  private relocate;
83
+ /**
84
+ * Answer a visible warning the way "I'm here" does — for a line the page
85
+ * itself sends the avatar (CA-1247). Does nothing when nothing is shown.
86
+ */
87
+ continueSession(): void;
83
88
  /**
84
89
  * Handle continue button click
85
90
  */
@@ -18,6 +18,8 @@ export declare function createPiPManager(handlers: {
18
18
  onEnd: () => void;
19
19
  onScreenShareToggle: () => void;
20
20
  isScreenShareSupported: () => boolean;
21
+ /** `features.captions.enabled`, read when the window opens (CA-1147). */
22
+ captionsEnabled?: () => boolean;
21
23
  onInteraction?: () => void;
22
24
  /**
23
25
  * PiP window opened — receives its #np_companion-sdk-root stage so callers
@@ -32,9 +32,12 @@ export interface ContainerSizeWatcher {
32
32
  * the container's content area, so the host's border and padding are already
33
33
  * subtracted — which is what the integrator has to account for.
34
34
  *
35
- * - `controls-width`: the control row sticks out of its pill. `requiredPx` is
36
- * the available width plus the overflow, i.e. the smallest room the row fits
37
- * in.
35
+ * - `controls-width`: the control row eats into the padding of the button
36
+ * bar inside its pill, or sticks out of the pill. `requiredPx` is the
37
+ * available width plus the shortfall, i.e. the smallest room the row fits
38
+ * in with the padding intact. The pill
39
+ * shrinks with the room, and a row flush with its edges is already cut by
40
+ * the pill's rounded ends, so the padding counts.
38
41
  * - `controls-height`: the pill is cut off by the top or bottom of the room.
39
42
  * - `entry-text`: the entry-point card's text is clipped.
40
43
  *
@@ -36,4 +36,14 @@ export declare const ControlIcons: {
36
36
  screenShare(): SVGSVGElement;
37
37
  screenShareActive(): SVGSVGElement;
38
38
  end(): SVGSVGElement;
39
+ /**
40
+ * Closed captions (CA-1147): a rounded frame with two "C"s, drawn as
41
+ * strokes so it matches the stroke set's weight. No Figma source yet —
42
+ * the designs predate the captions button. Like the mute buttons, both
43
+ * states keep the bar's colour and differ by shape: crossed out while
44
+ * captions are off (it was green when on; the manager asked for it to
45
+ * look like the other buttons).
46
+ */
47
+ captions(): SVGSVGElement;
48
+ captionsOff(): SVGSVGElement;
39
49
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@touchcastllc/napster-companion-api-dev",
3
- "version": "2.1.0-alpha.5",
3
+ "version": "2.1.0-alpha.7",
4
4
  "keywords": [
5
5
  "napster",
6
6
  "companion-api",