@touchcastllc/napster-companion-api-dev 2.1.0-alpha.0 → 2.1.0-alpha.10
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 +32 -17
- package/lib/button/trigger.d.ts +2 -0
- package/lib/components/Avatar/controlsAutoHide.d.ts +3 -1
- package/lib/components/Avatar/index.d.ts +1 -0
- package/lib/components/Captions/index.d.ts +27 -0
- package/lib/components/Embed/index.d.ts +1 -0
- package/lib/components/controls/createCaptionsButton.d.ts +7 -0
- package/lib/components/controls/index.d.ts +1 -0
- package/lib/constants/events.d.ts +4 -2
- package/lib/index.css +5 -1
- package/lib/index.d.ts +6 -7
- package/lib/index.esm.js +1 -1
- package/lib/index.js +1 -1
- package/lib/index.standalone.js +1 -1
- package/lib/persistence/index.d.ts +9 -0
- package/lib/services/captions.d.ts +94 -0
- package/lib/services/sessionAnnouncements.d.ts +2 -0
- package/lib/stores/index.d.ts +1 -1
- package/lib/stores/selectors.d.ts +2 -1
- package/lib/stores/slices/avatarSlice.d.ts +3 -2
- package/lib/types/errors.d.ts +1 -18
- package/lib/types/index.d.ts +29 -101
- package/lib/utils/InactiveOverlayManager.d.ts +5 -0
- package/lib/utils/PiPManager.d.ts +2 -0
- package/lib/utils/accentColor.d.ts +43 -0
- package/lib/utils/containerSizeWatcher.d.ts +6 -3
- package/lib/utils/fixedFitScale.d.ts +24 -0
- package/lib/utils/layoutScale.d.ts +8 -0
- package/lib/utils/svg.d.ts +10 -0
- package/lib/utils/tabStartGuard.d.ts +21 -0
- package/package.json +2 -12
- package/lib/services/faceTracking.d.ts +0 -13
- package/lib/utils/mouthDetection.d.ts +0 -24
|
@@ -63,6 +63,15 @@ export interface PersistenceController {
|
|
|
63
63
|
* whatever it had underneath.
|
|
64
64
|
*/
|
|
65
65
|
end(): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Session over, but no reload owed for it (a failed token, a dropped connection, the
|
|
68
|
+
* widget being disposed): reveal the page in place while the frame still shows the
|
|
69
|
+
* page the tab is on; once the visitor has navigated inside the frame, leave like
|
|
70
|
+
* `end()` — a top-level load of the frame's page — because revealing would show the
|
|
71
|
+
* page they started on under the url of the one they moved to (CA-1250). Returns
|
|
72
|
+
* `true` if it navigated.
|
|
73
|
+
*/
|
|
74
|
+
unwrap(): boolean;
|
|
66
75
|
/** Remove the iframe + listeners WITHOUT navigating (for a full teardown/destroy). */
|
|
67
76
|
teardown(): void;
|
|
68
77
|
}
|
|
@@ -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
|
};
|
package/lib/stores/index.d.ts
CHANGED
|
@@ -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,
|
|
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";
|
|
@@ -11,9 +11,10 @@ export declare const selectMuted: (state: RootState) => boolean;
|
|
|
11
11
|
export declare const selectMicUnavailable: (state: RootState) => boolean;
|
|
12
12
|
export declare const selectMicRecoveryOpen: (state: RootState) => boolean;
|
|
13
13
|
export declare const selectMicSourceMuted: (state: RootState) => boolean;
|
|
14
|
-
export declare const selectAutoMicActive: (state: RootState) => boolean;
|
|
15
14
|
export declare const selectAvatarSpeaking: (state: RootState) => boolean;
|
|
16
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;
|
|
17
18
|
export declare const selectConnectionToken: (state: RootState) => string | undefined;
|
|
18
19
|
export declare const selectStopInteraction: (state: RootState) => boolean;
|
|
19
20
|
export declare const selectCloseConnectionHandler: (state: RootState) => (() => void) | undefined;
|
|
@@ -7,14 +7,15 @@ export interface AvatarState {
|
|
|
7
7
|
micUnavailable: boolean;
|
|
8
8
|
micRecoveryOpen: boolean;
|
|
9
9
|
micSourceMuted: boolean;
|
|
10
|
-
autoMicActive: boolean;
|
|
11
10
|
volume: number;
|
|
12
11
|
avatarSpeaking: boolean;
|
|
13
12
|
isScreenSharing: boolean;
|
|
14
13
|
isUserTalking: boolean;
|
|
14
|
+
captionsOn: boolean;
|
|
15
|
+
caption: string | null;
|
|
15
16
|
connectionToken?: string;
|
|
16
17
|
closeConnectionHandler?: () => void;
|
|
17
18
|
sessionTerminatedByServer: boolean;
|
|
18
19
|
}
|
|
19
|
-
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">,
|
|
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">;
|
|
20
21
|
export declare const avatarReducer: import("redux").Reducer<AvatarState>;
|
package/lib/types/errors.d.ts
CHANGED
|
@@ -42,24 +42,12 @@ export declare class ConnectionError extends SDKError {
|
|
|
42
42
|
export declare class WebRTCError extends SDKError {
|
|
43
43
|
constructor(message: string, context?: Record<string, unknown>);
|
|
44
44
|
}
|
|
45
|
-
/**
|
|
46
|
-
* Feature related errors
|
|
47
|
-
*/
|
|
48
|
-
export declare class FeatureError extends SDKError {
|
|
49
|
-
constructor(message: string, context?: Record<string, unknown>);
|
|
50
|
-
}
|
|
51
45
|
/**
|
|
52
46
|
* Media related errors (video, audio)
|
|
53
47
|
*/
|
|
54
48
|
export declare class MediaError extends SDKError {
|
|
55
49
|
constructor(message: string, context?: Record<string, unknown>);
|
|
56
50
|
}
|
|
57
|
-
/**
|
|
58
|
-
* Face tracking related errors
|
|
59
|
-
*/
|
|
60
|
-
export declare class FaceTrackingError extends SDKError {
|
|
61
|
-
constructor(message: string, code: string, context?: Record<string, unknown>);
|
|
62
|
-
}
|
|
63
51
|
/**
|
|
64
52
|
* Error codes enum for consistent error identification
|
|
65
53
|
*/
|
|
@@ -80,14 +68,9 @@ export declare enum ErrorCodes {
|
|
|
80
68
|
INVALID_CONFIGURATION = "INVALID_CONFIGURATION",
|
|
81
69
|
MISSING_REQUIRED_CONFIG = "MISSING_REQUIRED_CONFIG",
|
|
82
70
|
FEATURE_NOT_SUPPORTED = "FEATURE_NOT_SUPPORTED",
|
|
83
|
-
FEATURE_DISABLED = "FEATURE_DISABLED",
|
|
84
71
|
MEDIA_ACCESS_DENIED = "MEDIA_ACCESS_DENIED",
|
|
85
72
|
MEDIA_DEVICE_ERROR = "MEDIA_DEVICE_ERROR",
|
|
86
|
-
VIDEO_LOAD_ERROR = "VIDEO_LOAD_ERROR"
|
|
87
|
-
CAMERA_PERMISSION_DENIED = "CAMERA_PERMISSION_DENIED",
|
|
88
|
-
CAMERA_NOT_FOUND = "CAMERA_NOT_FOUND",
|
|
89
|
-
MODEL_LOAD_FAILED = "MODEL_LOAD_FAILED",
|
|
90
|
-
DETECTION_FAILED = "DETECTION_FAILED"
|
|
73
|
+
VIDEO_LOAD_ERROR = "VIDEO_LOAD_ERROR"
|
|
91
74
|
}
|
|
92
75
|
/**
|
|
93
76
|
* Type guard to check if an error is an SDK error
|
package/lib/types/index.d.ts
CHANGED
|
@@ -15,19 +15,6 @@ export declare enum Position {
|
|
|
15
15
|
TOP_LEFT = "top-left",
|
|
16
16
|
CENTER = "center"
|
|
17
17
|
}
|
|
18
|
-
/**
|
|
19
|
-
* Function definition for AI companion function calling.
|
|
20
|
-
* Functions allow the AI companion to invoke external tools or actions
|
|
21
|
-
* during a conversation.
|
|
22
|
-
*/
|
|
23
|
-
export interface CompanionFunction {
|
|
24
|
-
/** Unique function name the AI can invoke. */
|
|
25
|
-
name: string;
|
|
26
|
-
/** Human-readable description of what the function does. */
|
|
27
|
-
description?: string;
|
|
28
|
-
/** JSON-Schema style parameter definitions. */
|
|
29
|
-
parameters?: Record<string, unknown>;
|
|
30
|
-
}
|
|
31
18
|
/**
|
|
32
19
|
* A full function definition registered inline at runtime via
|
|
33
20
|
* `set_settings.inline_functions`. Mirrors the backend's function record: a
|
|
@@ -65,7 +52,10 @@ export interface SendMessageData {
|
|
|
65
52
|
trigger_response: boolean;
|
|
66
53
|
/** Optional ID of the previous message in the conversation thread */
|
|
67
54
|
previous_item_id?: string;
|
|
68
|
-
/**
|
|
55
|
+
/**
|
|
56
|
+
* With `trigger_response: true`, the agent finishes its current speech
|
|
57
|
+
* before replying.
|
|
58
|
+
*/
|
|
69
59
|
delay?: boolean;
|
|
70
60
|
}
|
|
71
61
|
/**
|
|
@@ -83,8 +73,11 @@ export type SetSettingsCommand = {
|
|
|
83
73
|
data: {
|
|
84
74
|
/** Session/connection modality (e.g. `"video"` for the avatar connection). */
|
|
85
75
|
modality?: string;
|
|
86
|
-
/**
|
|
87
|
-
|
|
76
|
+
/**
|
|
77
|
+
* IDs of functions already registered on the backend — not definitions.
|
|
78
|
+
* To register a definition at runtime, use `inline_functions`.
|
|
79
|
+
*/
|
|
80
|
+
functions?: string[];
|
|
88
81
|
/**
|
|
89
82
|
* Full function definitions provided inline at runtime. Used to register
|
|
90
83
|
* tools MID-SESSION — e.g. the WebMCP bridge pushes the page's live
|
|
@@ -116,7 +109,11 @@ export type FunctionCallOutputCommand = {
|
|
|
116
109
|
type: DataChannelMessageType.FUNCTION_CALL_OUTPUT;
|
|
117
110
|
data: FunctionCallOutputData;
|
|
118
111
|
};
|
|
119
|
-
|
|
112
|
+
/** Restarts the server's idle timer; the agent is told nothing (CA-1203). */
|
|
113
|
+
export type ResetInactivityTimeoutCommand = {
|
|
114
|
+
type: DataChannelMessageType.RESET_INACTIVITY_TIMEOUT;
|
|
115
|
+
};
|
|
116
|
+
export type DataChannelCommand = SendMessageCommand | CancelCommand | SetSettingsCommand | StartVideoCommand | StopVideoCommand | FunctionCallOutputCommand | ResetInactivityTimeoutCommand;
|
|
120
117
|
export declare const maxInactiveTimeoutDuration = 180000;
|
|
121
118
|
export declare const defaultCountdownDuration = 30;
|
|
122
119
|
/**
|
|
@@ -133,10 +130,14 @@ export interface EventMessage {
|
|
|
133
130
|
event: string;
|
|
134
131
|
data?: {
|
|
135
132
|
state?: string;
|
|
133
|
+
/** `talk_state_changed`: the reply being spoken — its message's `item_id`. */
|
|
134
|
+
talk_id?: string;
|
|
136
135
|
message?: {
|
|
137
136
|
action?: string;
|
|
138
137
|
content?: string;
|
|
139
138
|
role?: string;
|
|
139
|
+
/** The reply this delta/completed message belongs to. */
|
|
140
|
+
item_id?: string;
|
|
140
141
|
};
|
|
141
142
|
/**
|
|
142
143
|
* Present on `avatar_state_changed` events for a deferred-video session
|
|
@@ -200,7 +201,6 @@ export interface FeatureConfig {
|
|
|
200
201
|
enabled: boolean;
|
|
201
202
|
/** Optional text shown when the disclaimer is enabled. */
|
|
202
203
|
text?: string;
|
|
203
|
-
color?: string;
|
|
204
204
|
};
|
|
205
205
|
/** Document Picture-in-Picture. When enabled, the avatar automatically
|
|
206
206
|
* opens in a PiP window when the user switches browser tabs (Chrome/Edge 116+). */
|
|
@@ -215,6 +215,13 @@ export interface FeatureConfig {
|
|
|
215
215
|
screenShare?: {
|
|
216
216
|
enabled: boolean;
|
|
217
217
|
};
|
|
218
|
+
/** Live captions of the avatar's speech (WCAG 1.2.4 Captions (Live)). The
|
|
219
|
+
* control bar gets a captions button; captions stay hidden until the user
|
|
220
|
+
* turns them on there. The text is the avatar's own, in the language it
|
|
221
|
+
* speaks. Defaults to `enabled: false`. */
|
|
222
|
+
captions?: {
|
|
223
|
+
enabled: boolean;
|
|
224
|
+
};
|
|
218
225
|
/** Built-in controls block (mute/volume/screen-share/end buttons) rendered over
|
|
219
226
|
* the avatar. Disable when the embedding app provides its own UI for these
|
|
220
227
|
* actions (e.g. via `muteMic`/`unmuteMic`, `stopAvatarTalking`, etc.).
|
|
@@ -222,15 +229,6 @@ export interface FeatureConfig {
|
|
|
222
229
|
controls?: {
|
|
223
230
|
enabled: boolean;
|
|
224
231
|
};
|
|
225
|
-
/** Face tracking feature. When enabled, opens the user's camera and runs
|
|
226
|
-
* real-time face mesh detection via TensorFlow.js + MediaPipe. */
|
|
227
|
-
faceTracking?: {
|
|
228
|
-
enabled: boolean;
|
|
229
|
-
/** Detection rate in FPS. Default 15, max 30. */
|
|
230
|
-
fps?: number;
|
|
231
|
-
/** Mouth opening ratio threshold. Default 0.015. */
|
|
232
|
-
talkingThreshold?: number;
|
|
233
|
-
};
|
|
234
232
|
/** The "big card" placeholder (blurred companion photo + spinner) shown
|
|
235
233
|
* behind the entry/loading/permission-pending/permission-blocked states,
|
|
236
234
|
* and the zoom-in grow animation played when the session becomes ready.
|
|
@@ -244,70 +242,6 @@ export interface FeatureConfig {
|
|
|
244
242
|
enabled: boolean;
|
|
245
243
|
};
|
|
246
244
|
}
|
|
247
|
-
/**
|
|
248
|
-
* Configuration for the face tracking service.
|
|
249
|
-
*/
|
|
250
|
-
export interface FaceTrackingConfig {
|
|
251
|
-
/** Detection rate in frames per second. Default 15, max 30. */
|
|
252
|
-
fps?: number;
|
|
253
|
-
/** Mouth opening ratio threshold to determine talking state. Default 0.015. */
|
|
254
|
-
talkingThreshold?: number;
|
|
255
|
-
/** Number of frames for rolling average smoothing. Default 5. */
|
|
256
|
-
smoothingFrames?: number;
|
|
257
|
-
/** Camera video width. Default 640. */
|
|
258
|
-
videoWidth?: number;
|
|
259
|
-
/** Camera video height. Default 480. */
|
|
260
|
-
videoHeight?: number;
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* Normalized mouth landmark positions (0–1 range).
|
|
264
|
-
*/
|
|
265
|
-
export interface MouthLandmarks {
|
|
266
|
-
topLip: {
|
|
267
|
-
x: number;
|
|
268
|
-
y: number;
|
|
269
|
-
};
|
|
270
|
-
bottomLip: {
|
|
271
|
-
x: number;
|
|
272
|
-
y: number;
|
|
273
|
-
};
|
|
274
|
-
leftCorner: {
|
|
275
|
-
x: number;
|
|
276
|
-
y: number;
|
|
277
|
-
};
|
|
278
|
-
rightCorner: {
|
|
279
|
-
x: number;
|
|
280
|
-
y: number;
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* Face tracking data emitted on each detection frame.
|
|
285
|
-
*/
|
|
286
|
-
export interface FaceTrackingData {
|
|
287
|
-
/** 468 normalized face landmarks (x, y, z in 0–1 range). */
|
|
288
|
-
landmarks: Array<{
|
|
289
|
-
x: number;
|
|
290
|
-
y: number;
|
|
291
|
-
z: number;
|
|
292
|
-
}>;
|
|
293
|
-
/** Normalized mouth landmark positions, or null if not detected. */
|
|
294
|
-
mouthLandmarks: MouthLandmarks | null;
|
|
295
|
-
/** Whether the user is currently talking based on smoothed mouth-opening ratio. */
|
|
296
|
-
isTalking: boolean;
|
|
297
|
-
}
|
|
298
|
-
/**
|
|
299
|
-
* Controller returned by createFaceTrackingService for managing the detection lifecycle.
|
|
300
|
-
*/
|
|
301
|
-
export interface FaceTrackingController {
|
|
302
|
-
/** Initialize camera + model and start the detection loop. */
|
|
303
|
-
start(): Promise<void>;
|
|
304
|
-
/** Pause detection and stop camera, but keep the model loaded for fast restart. */
|
|
305
|
-
stop(): void;
|
|
306
|
-
/** Whether the detection loop is currently running. */
|
|
307
|
-
isActive(): boolean;
|
|
308
|
-
/** Full teardown: stop + dispose model + null all refs. */
|
|
309
|
-
destroy(): void;
|
|
310
|
-
}
|
|
311
245
|
export interface StyleConfig {
|
|
312
246
|
/** Avatar visual style: "round" | "rectangle" | "silhouette" (Default: "round").
|
|
313
247
|
*
|
|
@@ -322,6 +256,10 @@ export interface StyleConfig {
|
|
|
322
256
|
* photo bubble's own ring. Does NOT affect the muted-mic button (a fixed
|
|
323
257
|
* warning color, not brand-tied) or `persistence.navigationProgress`'s
|
|
324
258
|
* own color (set separately — see {@link NavigationProgressOptions}).
|
|
259
|
+
*
|
|
260
|
+
* Text and icons on the accent are white or black, whichever contrasts
|
|
261
|
+
* more with it, so any accent stays readable (WCAG 1.4.3). The SDK picks
|
|
262
|
+
* them; they can't be set.
|
|
325
263
|
*/
|
|
326
264
|
accentColor?: string;
|
|
327
265
|
/** CSS class name(s) added to the SDK root container. Useful for theming. */
|
|
@@ -608,12 +546,8 @@ export interface NapsterCompanionApiConfig {
|
|
|
608
546
|
onDestroy?: () => void;
|
|
609
547
|
/** Called whenever feature configuration is changed at runtime. */
|
|
610
548
|
onFeaturesUpdate?: (features: FeatureConfig) => void;
|
|
611
|
-
/** Called on each face tracking detection frame with face data (or null if no face detected). */
|
|
612
|
-
onFaceTrackingData?: (data: FaceTrackingData | null) => void;
|
|
613
549
|
/** Called when the screen share state changes (started or stopped). */
|
|
614
550
|
onScreenShareStateChange?: (isSharing: boolean) => void;
|
|
615
|
-
/** Called when a face tracking error occurs (camera denied, model load failure, etc.). */
|
|
616
|
-
onFaceTrackingError?: (error: Error) => void;
|
|
617
551
|
}
|
|
618
552
|
/**
|
|
619
553
|
* Public instance returned by `init`. Use these methods to control the
|
|
@@ -635,8 +569,6 @@ export interface NapsterCompanionApiInstance {
|
|
|
635
569
|
readonly sessionId: string | undefined;
|
|
636
570
|
/** Set the position of the SDK on screen (see `Position`). */
|
|
637
571
|
setPosition: (position: Position) => void;
|
|
638
|
-
/** Clear any programmatic position and revert to the configured/default position. */
|
|
639
|
-
clearPosition: () => void;
|
|
640
572
|
/** Update style configuration (e.g., view: round/silhouette/rectangle). */
|
|
641
573
|
updateStyle: (newStyle: Partial<NonNullable<NapsterCompanionApiConfig["style"]>>) => void;
|
|
642
574
|
/** Enable a named feature (one of the keys from `FeatureConfig`).
|
|
@@ -670,10 +602,6 @@ export interface NapsterCompanionApiInstance {
|
|
|
670
602
|
readonly isScreenSharing: boolean;
|
|
671
603
|
/** Whether screen sharing is supported by the browser and enabled in config. */
|
|
672
604
|
readonly isScreenShareSupported: boolean;
|
|
673
|
-
/** Start face tracking (opens camera, loads model, begins detection loop). */
|
|
674
|
-
startFaceTracking: () => Promise<void>;
|
|
675
|
-
/** Stop face tracking (pauses detection, stops camera; model stays loaded for fast restart). */
|
|
676
|
-
stopFaceTracking: () => void;
|
|
677
605
|
/** Mute the avatar's audio output. */
|
|
678
606
|
muteAudio: () => void;
|
|
679
607
|
/** Unmute the avatar's audio output. */
|
|
@@ -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
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `style.accentColor` is the background of text and icons: the mic button,
|
|
3
|
+
* the "I'm here" and microphone-card buttons, the no-photo bubble. The SDK,
|
|
4
|
+
* not the integrator, picks white or black for them, whichever contrasts
|
|
5
|
+
* more with the accent — at least 4.58:1 for any colour (CA-1278).
|
|
6
|
+
*
|
|
7
|
+
* Everything reaches CSS as custom properties on the root, each with a
|
|
8
|
+
* fallback in the stylesheets that reproduces the default accent:
|
|
9
|
+
* --np-accent-color the accent itself
|
|
10
|
+
* --np-accent-text #ffffff or #000000
|
|
11
|
+
* --np-accent-hover the hover background
|
|
12
|
+
* --np-accent-glyph-filter turns the white no-photo glyph black
|
|
13
|
+
* --np-accent-shade end of the mic button's darkening gradient;
|
|
14
|
+
* transparent under a black icon, where
|
|
15
|
+
* darkening would take it below 4.5:1
|
|
16
|
+
*/
|
|
17
|
+
export type Rgb = [number, number, number];
|
|
18
|
+
declare const WHITE = "#ffffff";
|
|
19
|
+
declare const BLACK = "#000000";
|
|
20
|
+
/** White or black, whichever has the higher WCAG contrast; white on a tie. */
|
|
21
|
+
export declare function accentTextColor(rgb: Rgb): typeof WHITE | typeof BLACK;
|
|
22
|
+
/**
|
|
23
|
+
* The hover background: 15% away from the text colour — darker under white
|
|
24
|
+
* text, lighter under black — so hovering only ever raises the contrast.
|
|
25
|
+
* For the default accent this is the old `color-mix(… 85%, black)`.
|
|
26
|
+
*/
|
|
27
|
+
export declare function accentHoverColor(rgb: Rgb): string;
|
|
28
|
+
/**
|
|
29
|
+
* Any CSS colour string as sRGB, the way the browser draws it (hex, rgb(),
|
|
30
|
+
* hsl(), oklch(), names…), or null if it isn't a colour. A canvas, not
|
|
31
|
+
* getComputedStyle, because computed colours keep their own space
|
|
32
|
+
* (`oklch(…)` stays `oklch(…)`).
|
|
33
|
+
*/
|
|
34
|
+
export declare function parseCssColor(css: string): Rgb | null;
|
|
35
|
+
/**
|
|
36
|
+
* Sets the accent and the colours derived from it on `el`. When the accent
|
|
37
|
+
* can't be read, the derived ones are removed and the stylesheets'
|
|
38
|
+
* defaults (white text, darker hover) apply.
|
|
39
|
+
*/
|
|
40
|
+
export declare function applyAccentColor(el: HTMLElement, accent: string, parse?: (css: string) => Rgb | null): void;
|
|
41
|
+
/** Copies the accent and its derived colours from one element to another. */
|
|
42
|
+
export declare function copyAccentColor(from: HTMLElement, to: HTMLElement): void;
|
|
43
|
+
export {};
|
|
@@ -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
|
|
36
|
-
*
|
|
37
|
-
*
|
|
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
|
*
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CA-1240 — a fixed widget is sized in CSS pixels, so zooming the page grows
|
|
3
|
+
* it with everything else: at 400% it covered most of a 320px-wide window
|
|
4
|
+
* and the page controls under it (WCAG 2.4.11, 1.4.10). Past 40% of the
|
|
5
|
+
* window's width the widget stops growing: it is scaled down as a whole —
|
|
6
|
+
* buttons, text and cards alike — so its layout never changes, only its
|
|
7
|
+
* drawn size.
|
|
8
|
+
*
|
|
9
|
+
* The factor goes on the root as `--np-fit-scale`; App.css applies it with
|
|
10
|
+
* `scale`, anchored on the corner the widget is docked to. Nothing is set
|
|
11
|
+
* while the widget fits, in inline layout (the host sizes the container),
|
|
12
|
+
* or on touch devices: a phone is narrow at 100% zoom, and shrinking the
|
|
13
|
+
* buttons there would only make them harder to tap.
|
|
14
|
+
*/
|
|
15
|
+
/** The widest a fixed widget may be, as a share of the window's width. */
|
|
16
|
+
export declare const MAX_WINDOW_SHARE = 0.4;
|
|
17
|
+
export interface FixedFitScale {
|
|
18
|
+
/** Measure again now. */
|
|
19
|
+
check(): void;
|
|
20
|
+
destroy(): void;
|
|
21
|
+
}
|
|
22
|
+
/** The scale that keeps a `widgetWidth` widget within its share of the window. */
|
|
23
|
+
export declare function fitScale(widgetWidth: number, windowWidth: number): number;
|
|
24
|
+
export declare function createFixedFitScale(root: HTMLElement): FixedFitScale;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How much smaller (or larger) `el` is drawn than it is laid out: the fixed
|
|
3
|
+
* widget is scaled down in a narrow window (fixedFitScale.ts, CA-1240).
|
|
4
|
+
* getBoundingClientRect() reports drawn sizes, CSS lengths are layout sizes —
|
|
5
|
+
* divide a rect-derived number by this before writing it into a style.
|
|
6
|
+
* 1 while nothing is laid out.
|
|
7
|
+
*/
|
|
8
|
+
export declare function layoutScale(el: HTMLElement): number;
|
package/lib/utils/svg.d.ts
CHANGED
|
@@ -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
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keeps Tab inside the widget after a click on empty space in it (CA-1141,
|
|
3
|
+
* tester's comment).
|
|
4
|
+
*
|
|
5
|
+
* Firefox starts sequential focus navigation from the selection, not from
|
|
6
|
+
* the clicked point, and a click on empty space snaps the selection into the
|
|
7
|
+
* nearest leaf, which next to the control bar is a button's icon. A click
|
|
8
|
+
* under the bar put it in "End session", the last button on the page, so the
|
|
9
|
+
* next Tab left the page for the browser's tab strip; a click above it
|
|
10
|
+
* skipped "Mute sound". Chrome and Safari start from the clicked node, where
|
|
11
|
+
* no button holds the selection, so this never acts there.
|
|
12
|
+
*
|
|
13
|
+
* The selection is moved to the start of the button's control group, or just
|
|
14
|
+
* before a button that has none, so Tab reaches the first control.
|
|
15
|
+
*
|
|
16
|
+
* The listener is on the document, not on the root: a click listener on an
|
|
17
|
+
* element makes VoiceOver announce everything inside it as "clickable" —
|
|
18
|
+
* the video and the "Avatar is ready" text included (found live, Safari and
|
|
19
|
+
* Firefox). Returns the function that removes it.
|
|
20
|
+
*/
|
|
21
|
+
export declare function guardTabStart(root: HTMLElement): () => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@touchcastllc/napster-companion-api-dev",
|
|
3
|
-
"version": "2.1.0-alpha.
|
|
3
|
+
"version": "2.1.0-alpha.10",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"napster",
|
|
6
6
|
"companion-api",
|
|
@@ -38,17 +38,7 @@
|
|
|
38
38
|
"!lib/**/*.spec.*"
|
|
39
39
|
],
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"@reduxjs/toolkit": "^2.0.0"
|
|
42
|
-
"@tensorflow-models/face-landmarks-detection": "^1.0.0",
|
|
43
|
-
"@tensorflow/tfjs": "^4.0.0"
|
|
44
|
-
},
|
|
45
|
-
"peerDependenciesMeta": {
|
|
46
|
-
"@tensorflow/tfjs": {
|
|
47
|
-
"optional": true
|
|
48
|
-
},
|
|
49
|
-
"@tensorflow-models/face-landmarks-detection": {
|
|
50
|
-
"optional": true
|
|
51
|
-
}
|
|
41
|
+
"@reduxjs/toolkit": "^2.0.0"
|
|
52
42
|
},
|
|
53
43
|
"publishConfig": {
|
|
54
44
|
"access": "public"
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { FaceTrackingConfig, FaceTrackingData, FaceTrackingController } from "../types";
|
|
2
|
-
interface FaceTrackingCallbacks {
|
|
3
|
-
onData?: (data: FaceTrackingData | null) => void;
|
|
4
|
-
onError?: (error: Error) => void;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Creates a vanilla-JS face tracking service using TensorFlow.js + MediaPipe Face Mesh.
|
|
8
|
-
*
|
|
9
|
-
* Lazy-loads @tensorflow/tfjs and @tensorflow-models/face-landmarks-detection
|
|
10
|
-
* only when start() is called, keeping the main bundle small (~2MB deferred).
|
|
11
|
-
*/
|
|
12
|
-
export declare function createFaceTrackingService(config?: FaceTrackingConfig, callbacks?: FaceTrackingCallbacks): FaceTrackingController;
|
|
13
|
-
export {};
|