@keyframelabs/elements 0.3.0 → 0.4.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 +89 -1
- package/dist/KflEmbedElement.d.ts +55 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +582 -128
- package/dist/kfl-embed-register.d.ts +1 -0
- package/dist/kfl-embed.js +18690 -0
- package/package.json +7 -4
package/README.md
CHANGED
|
@@ -18,9 +18,10 @@ pnpm add @keyframelabs/elements
|
|
|
18
18
|
|
|
19
19
|
## Usage
|
|
20
20
|
|
|
21
|
-
This package provides
|
|
21
|
+
This package provides three integration options depending on your strategy:
|
|
22
22
|
1. **`PersonaEmbed`**: Fully managed. Uses a publishable key. Best for rapid frontend integration.
|
|
23
23
|
2. **`PersonaView`**: Bring your own backend. Uses session tokens generated by your server.
|
|
24
|
+
3. **`<kfl-embed>`**: Drop-in web component. Wraps `PersonaEmbed` with a complete widget UI (states, controls, positioning). Zero framework dependencies.
|
|
24
25
|
|
|
25
26
|
### Option A: PersonaEmbed (managed)
|
|
26
27
|
|
|
@@ -69,6 +70,93 @@ await view.connect();
|
|
|
69
70
|
view.disconnect();
|
|
70
71
|
```
|
|
71
72
|
|
|
73
|
+
### Option C: `<kfl-embed>` Web Component
|
|
74
|
+
|
|
75
|
+
A self-registering custom element that wraps `PersonaEmbed` with a widget UI shell: minimized/active/hidden states, "Join call" button, minimize/expand toggle, corner positioning, and button color styling. Drop it into any page with zero framework dependencies.
|
|
76
|
+
|
|
77
|
+
```html
|
|
78
|
+
<kfl-embed
|
|
79
|
+
publishable-key="kfl_pk_live_..."
|
|
80
|
+
initial-state="minimized"
|
|
81
|
+
corner="bottom-right"
|
|
82
|
+
minimized-width="144"
|
|
83
|
+
minimized-height="216"
|
|
84
|
+
active-width="252"
|
|
85
|
+
active-height="377"
|
|
86
|
+
button-color="#919191"
|
|
87
|
+
button-color-opacity="0.3"
|
|
88
|
+
video-fit="cover"
|
|
89
|
+
preview-image="https://example.com/avatar.png"></kfl-embed>
|
|
90
|
+
<script type="module" src="https://unpkg.com/@keyframelabs/elements/dist/kfl-embed.js"></script>
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
#### Attributes
|
|
94
|
+
|
|
95
|
+
| Attribute | Type | Default | Description |
|
|
96
|
+
| -------------------------------- | ---------------------------------------------------------- | ---------------- | ------------------------------------------------------------------ |
|
|
97
|
+
| `publishable-key` | `string` | Required | Your publishable embed key. |
|
|
98
|
+
| `api-base-url` | `string` | Keyframe default | Base URL for the Keyframe API. |
|
|
99
|
+
| `initial-state` | `'minimized' \| 'active' \| 'hidden'` | `'minimized'` | Widget state on first load. |
|
|
100
|
+
| `controlled-widget-state` | `'minimized' \| 'active' \| 'hidden'` | — | Externally control the widget state (overrides internal state). |
|
|
101
|
+
| `corner` | `'bottom-right' \| 'bottom-left' \| 'top-right' \| 'top-left'` | `'bottom-right'` | Which corner to anchor the widget (fixed mode only). |
|
|
102
|
+
| `inline` | boolean attribute | — | Use `position: relative` instead of `fixed`. |
|
|
103
|
+
| `minimized-width` | `number` | `144` | Width in px when minimized. |
|
|
104
|
+
| `minimized-height` | `number` | `216` | Height in px when minimized. |
|
|
105
|
+
| `active-width` | `number` | `252` | Width in px when active (in-call). |
|
|
106
|
+
| `active-height` | `number` | `377` | Height in px when active (in-call). |
|
|
107
|
+
| `hide-ui` | boolean attribute | — | Hides all overlay controls. Useful for building your own UI shell. |
|
|
108
|
+
| `show-minimize-button` | `'true' \| 'false'` | `'true'` | Show the X/minimize button on hover. |
|
|
109
|
+
| `controlled-show-minimize-button`| `'true' \| 'false'` | — | Externally control the minimize button visibility. |
|
|
110
|
+
| `button-color` | hex color string | `'#919191'` | Color of the "Join call" button. |
|
|
111
|
+
| `button-color-opacity` | `number` (0–1) | `0.3` | Opacity of the "Join call" button background. |
|
|
112
|
+
| `video-fit` | `'cover' \| 'contain'` | `'cover'` | Video scaling mode. |
|
|
113
|
+
| `preview-image` | URL string | — | Image shown in the widget before a call starts. |
|
|
114
|
+
|
|
115
|
+
#### Events
|
|
116
|
+
|
|
117
|
+
| Event | `detail` | Description |
|
|
118
|
+
| ------------------ | --------------------------------------- | -------------------------------------- |
|
|
119
|
+
| `statechange` | `{ status: EmbedStatus }` | Connection status changed. |
|
|
120
|
+
| `agentstatechange` | `{ state: AgentState }` | Avatar playback state changed. |
|
|
121
|
+
| `widgetstatechange`| `{ state: 'minimized' \| 'active' \| 'hidden' }` | Widget UI state changed. |
|
|
122
|
+
| `disconnected` | — | Session disconnected. |
|
|
123
|
+
| `error` | `{ error: Error }` | A fatal error occurred. |
|
|
124
|
+
|
|
125
|
+
#### JavaScript API
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
const el = document.querySelector('kfl-embed');
|
|
129
|
+
|
|
130
|
+
await el.micOn(); // Start session if needed, then unmute mic
|
|
131
|
+
await el.micOff(); // Mute mic
|
|
132
|
+
el.isMicOn(); // boolean
|
|
133
|
+
|
|
134
|
+
await el.mute(); // Mute speaker audio
|
|
135
|
+
await el.unmute(); // Unmute speaker audio
|
|
136
|
+
el.isMuted(); // boolean
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
#### Build
|
|
140
|
+
|
|
141
|
+
The web component is built as a self-contained ES module via `vite.config.embed.ts`:
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
pnpm build:embed # → dist/kfl-embed.js
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Import the auto-registering entry point (registers `<kfl-embed>` on `customElements`):
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
import '@keyframelabs/elements/kfl-embed';
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Or import the class directly for manual registration:
|
|
154
|
+
|
|
155
|
+
```ts
|
|
156
|
+
import { KflEmbedElement } from '@keyframelabs/elements';
|
|
157
|
+
customElements.define('my-embed', KflEmbedElement);
|
|
158
|
+
```
|
|
159
|
+
|
|
72
160
|
## Supported agents and real-time LLMs
|
|
73
161
|
|
|
74
162
|
Supports ElevenLabs and OpenAI Realtime.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <kfl-embed> Web Component
|
|
3
|
+
*
|
|
4
|
+
* Composes PersonaEmbed internally -- does NOT reimplement session/video/audio logic.
|
|
5
|
+
* Adds the widget UI shell: minimized/active/hidden states, "Join call" button,
|
|
6
|
+
* minimize/expand toggle, corner positioning CSS, button color styling.
|
|
7
|
+
*/
|
|
8
|
+
export declare class KflEmbedElement extends HTMLElement {
|
|
9
|
+
static get observedAttributes(): ("publishable-key" | "api-base-url" | "initial-state" | "controlled-widget-state" | "active-width" | "active-height" | "minimized-width" | "minimized-height" | "inline" | "corner" | "hide-ui" | "show-minimize-button" | "controlled-show-minimize-button" | "button-color" | "button-color-opacity" | "video-fit" | "preview-image")[];
|
|
10
|
+
private shadow;
|
|
11
|
+
private embed;
|
|
12
|
+
private _widgetState;
|
|
13
|
+
private _connected;
|
|
14
|
+
private _connecting;
|
|
15
|
+
private widgetEl;
|
|
16
|
+
private innerEl;
|
|
17
|
+
private containerEl;
|
|
18
|
+
private previewImg;
|
|
19
|
+
private spinnerEl;
|
|
20
|
+
private errorToast;
|
|
21
|
+
private errorTimer;
|
|
22
|
+
private joinBtn;
|
|
23
|
+
private endCallBtn;
|
|
24
|
+
private toggleBtn;
|
|
25
|
+
private revealBtn;
|
|
26
|
+
private toolbarEl;
|
|
27
|
+
private micBtn;
|
|
28
|
+
constructor();
|
|
29
|
+
connectedCallback(): void;
|
|
30
|
+
disconnectedCallback(): void;
|
|
31
|
+
attributeChangedCallback(name: string, _old: string | null, value: string | null): void;
|
|
32
|
+
mute(): Promise<void>;
|
|
33
|
+
unmute(): Promise<void>;
|
|
34
|
+
isMuted(): boolean;
|
|
35
|
+
canUnmute(): boolean;
|
|
36
|
+
micOn(): Promise<void>;
|
|
37
|
+
micOff(): Promise<void>;
|
|
38
|
+
isMicOn(): boolean;
|
|
39
|
+
canTurnOnMic(): boolean;
|
|
40
|
+
setEmotion(_emotion: 'neutral' | 'angry' | 'sad' | 'happy'): void;
|
|
41
|
+
private _getAttrNum;
|
|
42
|
+
private _getCorner;
|
|
43
|
+
private _applyLayout;
|
|
44
|
+
private _applyState;
|
|
45
|
+
private _shouldShowMinimizeButton;
|
|
46
|
+
private _handleJoinCall;
|
|
47
|
+
private _handleToggle;
|
|
48
|
+
private _handleEndCall;
|
|
49
|
+
private _handleReveal;
|
|
50
|
+
private _handleMicToggle;
|
|
51
|
+
private _updateMicIcon;
|
|
52
|
+
private _resetToMinimized;
|
|
53
|
+
private _showError;
|
|
54
|
+
private _connect;
|
|
55
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,5 +7,6 @@ export { createAgent, ElevenLabsAgent, OpenAIRealtimeAgent, BaseAgent, AGENT_REG
|
|
|
7
7
|
export type { AgentType, AgentConfig, AgentEventMap, Agent, AnyAgent, AgentTypeInfo, ElevenLabsConfig, OpenAIRealtimeConfig, TurnDetection, } from './agents';
|
|
8
8
|
export type { AgentState } from '@keyframelabs/sdk';
|
|
9
9
|
export { floatTo16BitPCM, resamplePcm, base64ToBytes, bytesToBase64, SAMPLE_RATE, createEventEmitter, } from './agents';
|
|
10
|
+
export { KflEmbedElement } from './KflEmbedElement';
|
|
10
11
|
export { ApiError as KeyframeApiError } from './ApiError';
|
|
11
12
|
export type { ApiErrorPayload as KeyframeApiErrorPayload } from './ApiError';
|