@livekit/agents-plugin-liveavatar 0.0.0-next-20260624041820
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/LICENSE +201 -0
- package/README.md +81 -0
- package/dist/api.cjs +150 -0
- package/dist/api.cjs.map +1 -0
- package/dist/api.d.cts +81 -0
- package/dist/api.d.ts +81 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +128 -0
- package/dist/api.js.map +1 -0
- package/dist/avatar.cjs +527 -0
- package/dist/avatar.cjs.map +1 -0
- package/dist/avatar.d.cts +150 -0
- package/dist/avatar.d.ts +150 -0
- package/dist/avatar.d.ts.map +1 -0
- package/dist/avatar.js +511 -0
- package/dist/avatar.js.map +1 -0
- package/dist/index.cjs +36 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/log.cjs +30 -0
- package/dist/log.cjs.map +1 -0
- package/dist/log.d.cts +3 -0
- package/dist/log.d.ts +3 -0
- package/dist/log.d.ts.map +1 -0
- package/dist/log.js +6 -0
- package/dist/log.js.map +1 -0
- package/package.json +53 -0
- package/src/api.ts +203 -0
- package/src/avatar.ts +641 -0
- package/src/index.ts +19 -0
- package/src/log.ts +7 -0
package/dist/log.cjs
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var log_exports = {};
|
|
20
|
+
__export(log_exports, {
|
|
21
|
+
log: () => log
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(log_exports);
|
|
24
|
+
var import_agents = require("@livekit/agents");
|
|
25
|
+
const log = () => (0, import_agents.log)().child({ plugin: "liveavatar" });
|
|
26
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
27
|
+
0 && (module.exports = {
|
|
28
|
+
log
|
|
29
|
+
});
|
|
30
|
+
//# sourceMappingURL=log.cjs.map
|
package/dist/log.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/log.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2026 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { log as agentsLog } from '@livekit/agents';\nimport type { Logger } from 'pino';\n\nexport const log = (): Logger => agentsLog().child({ plugin: 'liveavatar' });\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAAiC;AAG1B,MAAM,MAAM,UAAc,cAAAA,KAAU,EAAE,MAAM,EAAE,QAAQ,aAAa,CAAC;","names":["agentsLog"]}
|
package/dist/log.d.cts
ADDED
package/dist/log.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEnC,eAAO,MAAM,GAAG,QAAO,MAAqD,CAAC"}
|
package/dist/log.js
ADDED
package/dist/log.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/log.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2026 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { log as agentsLog } from '@livekit/agents';\nimport type { Logger } from 'pino';\n\nexport const log = (): Logger => agentsLog().child({ plugin: 'liveavatar' });\n"],"mappings":"AAGA,SAAS,OAAO,iBAAiB;AAG1B,MAAM,MAAM,MAAc,UAAU,EAAE,MAAM,EAAE,QAAQ,aAAa,CAAC;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@livekit/agents-plugin-liveavatar",
|
|
3
|
+
"version": "0.0.0-next-20260624041820",
|
|
4
|
+
"description": "LiveAvatar avatar plugin for LiveKit Node Agents",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"require": "dist/index.cjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
"import": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"require": {
|
|
14
|
+
"types": "./dist/index.d.cts",
|
|
15
|
+
"default": "./dist/index.cjs"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"author": "LiveKit",
|
|
19
|
+
"type": "module",
|
|
20
|
+
"repository": "git@github.com:livekit/agents-js.git",
|
|
21
|
+
"license": "Apache-2.0",
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"src",
|
|
25
|
+
"README.md"
|
|
26
|
+
],
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@livekit/rtc-node": "^0.13.29",
|
|
29
|
+
"@microsoft/api-extractor": "^7.35.0",
|
|
30
|
+
"@types/ws": "^8.5.10",
|
|
31
|
+
"pino": "^8.19.0",
|
|
32
|
+
"tsup": "^8.3.5",
|
|
33
|
+
"typescript": "^5.0.0",
|
|
34
|
+
"@livekit/agents": "0.0.0-next-20260624041820"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"livekit-server-sdk": "^2.13.3",
|
|
38
|
+
"ws": "^8.18.0"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"@livekit/rtc-node": "^0.13.29",
|
|
42
|
+
"@livekit/agents": "0.0.0-next-20260624041820"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsup --onSuccess \"pnpm build:types\"",
|
|
46
|
+
"build:types": "tsc --declaration --emitDeclarationOnly && node ../../scripts/copyDeclarationOutput.js",
|
|
47
|
+
"clean": "rm -rf dist",
|
|
48
|
+
"clean:build": "pnpm clean && pnpm build",
|
|
49
|
+
"lint": "eslint -f unix \"src/**/*.{ts,js}\"",
|
|
50
|
+
"api:check": "api-extractor run --typescript-compiler-folder ../../node_modules/typescript",
|
|
51
|
+
"api:update": "api-extractor run --local --typescript-compiler-folder ../../node_modules/typescript --verbose"
|
|
52
|
+
}
|
|
53
|
+
}
|
package/src/api.ts
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 LiveKit, Inc.
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
import {
|
|
5
|
+
type APIConnectOptions,
|
|
6
|
+
APIConnectionError,
|
|
7
|
+
APIStatusError,
|
|
8
|
+
DEFAULT_API_CONNECT_OPTIONS,
|
|
9
|
+
} from '@livekit/agents';
|
|
10
|
+
import { log } from './log.js';
|
|
11
|
+
|
|
12
|
+
export const DEFAULT_API_URL = 'https://api.liveavatar.com/v1/sessions';
|
|
13
|
+
|
|
14
|
+
export type VideoQuality = 'very_high' | 'high' | 'medium' | 'low';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Exception thrown when the LiveAvatar plugin or the LiveAvatar service errors.
|
|
18
|
+
*/
|
|
19
|
+
export class LiveAvatarException extends Error {
|
|
20
|
+
constructor(message: string) {
|
|
21
|
+
super(message);
|
|
22
|
+
this.name = 'LiveAvatarException';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface CreateStreamingSessionOptions {
|
|
27
|
+
livekitUrl: string;
|
|
28
|
+
livekitToken: string;
|
|
29
|
+
roomName: string;
|
|
30
|
+
avatarId: string;
|
|
31
|
+
isSandbox?: boolean;
|
|
32
|
+
videoQuality?: VideoQuality | null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface SessionResponse {
|
|
36
|
+
data: {
|
|
37
|
+
session_id: string;
|
|
38
|
+
session_token: string;
|
|
39
|
+
[key: string]: unknown;
|
|
40
|
+
};
|
|
41
|
+
code: number;
|
|
42
|
+
[key: string]: unknown;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface StartSessionResponse {
|
|
46
|
+
data: {
|
|
47
|
+
ws_url: string;
|
|
48
|
+
[key: string]: unknown;
|
|
49
|
+
};
|
|
50
|
+
code: number;
|
|
51
|
+
[key: string]: unknown;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface StopSessionResponse {
|
|
55
|
+
data: Record<string, unknown>;
|
|
56
|
+
code: number;
|
|
57
|
+
[key: string]: unknown;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface LiveAvatarAPIOptions {
|
|
61
|
+
apiKey?: string;
|
|
62
|
+
apiUrl?: string;
|
|
63
|
+
connOptions?: APIConnectOptions;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Thin client for the LiveAvatar HTTP API.
|
|
68
|
+
*
|
|
69
|
+
* Mirrors `livekit-plugins/livekit-plugins-liveavatar/livekit/plugins/liveavatar/api.py`.
|
|
70
|
+
*/
|
|
71
|
+
export class LiveAvatarAPI {
|
|
72
|
+
private apiKey: string;
|
|
73
|
+
private apiUrl: string;
|
|
74
|
+
private connOptions: APIConnectOptions;
|
|
75
|
+
|
|
76
|
+
#logger = log();
|
|
77
|
+
|
|
78
|
+
constructor(options: LiveAvatarAPIOptions = {}) {
|
|
79
|
+
const apiKey = options.apiKey ?? process.env.LIVEAVATAR_API_KEY ?? '';
|
|
80
|
+
if (!apiKey) {
|
|
81
|
+
throw new LiveAvatarException('api_key or LIVEAVATAR_API_KEY must be set');
|
|
82
|
+
}
|
|
83
|
+
this.apiKey = apiKey;
|
|
84
|
+
this.apiUrl = options.apiUrl || DEFAULT_API_URL;
|
|
85
|
+
this.connOptions = options.connOptions || DEFAULT_API_CONNECT_OPTIONS;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Create a new streaming session, returning the session id and session token.
|
|
90
|
+
*
|
|
91
|
+
* Ref: python livekit-plugins/livekit-plugins-liveavatar/livekit/plugins/liveavatar/api.py - 51-87 lines
|
|
92
|
+
*/
|
|
93
|
+
async createStreamingSession(opts: CreateStreamingSessionOptions): Promise<SessionResponse> {
|
|
94
|
+
const livekitConfig = {
|
|
95
|
+
livekit_room: opts.roomName,
|
|
96
|
+
livekit_url: opts.livekitUrl,
|
|
97
|
+
livekit_client_token: opts.livekitToken,
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const payload: Record<string, unknown> = {
|
|
101
|
+
mode: 'LITE',
|
|
102
|
+
avatar_id: opts.avatarId,
|
|
103
|
+
is_sandbox: opts.isSandbox ?? false,
|
|
104
|
+
livekit_config: livekitConfig,
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
if (opts.videoQuality != null) {
|
|
108
|
+
payload.video_quality = opts.videoQuality;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const headers = {
|
|
112
|
+
accept: 'application/json',
|
|
113
|
+
'content-type': 'application/json',
|
|
114
|
+
'X-API-KEY': this.apiKey,
|
|
115
|
+
};
|
|
116
|
+
return (await this.post('/token', payload, headers)) as SessionResponse;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Start a previously created streaming session.
|
|
121
|
+
*
|
|
122
|
+
* Ref: python livekit-plugins/livekit-plugins-liveavatar/livekit/plugins/liveavatar/api.py - 92-97 lines
|
|
123
|
+
*/
|
|
124
|
+
async startStreamingSession(
|
|
125
|
+
sessionId: string,
|
|
126
|
+
sessionToken: string,
|
|
127
|
+
): Promise<StartSessionResponse> {
|
|
128
|
+
const payload = { session_id: sessionId };
|
|
129
|
+
const headers = {
|
|
130
|
+
'content-type': 'application/json',
|
|
131
|
+
Authorization: `Bearer ${sessionToken}`,
|
|
132
|
+
};
|
|
133
|
+
return (await this.post('/start', payload, headers)) as StartSessionResponse;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Stop a running streaming session.
|
|
138
|
+
*
|
|
139
|
+
* Ref: python livekit-plugins/livekit-plugins-liveavatar/livekit/plugins/liveavatar/api.py - 99-107 lines
|
|
140
|
+
*/
|
|
141
|
+
async stopStreamingSession(
|
|
142
|
+
sessionId: string,
|
|
143
|
+
sessionToken: string,
|
|
144
|
+
): Promise<StopSessionResponse> {
|
|
145
|
+
const payload = { session_id: sessionId, reason: 'USER_DISCONNECTED' };
|
|
146
|
+
const headers = {
|
|
147
|
+
'content-type': 'application/json',
|
|
148
|
+
Authorization: `Bearer ${sessionToken}`,
|
|
149
|
+
};
|
|
150
|
+
return (await this.post('/stop', payload, headers)) as StopSessionResponse;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* POST helper with the same retry/backoff semantics as the Python plugin.
|
|
155
|
+
*
|
|
156
|
+
* Ref: python livekit-plugins/livekit-plugins-liveavatar/livekit/plugins/liveavatar/api.py - 109-138 lines
|
|
157
|
+
*/
|
|
158
|
+
private async post(
|
|
159
|
+
endpoint: string,
|
|
160
|
+
payload: Record<string, unknown>,
|
|
161
|
+
headers: Record<string, string>,
|
|
162
|
+
): Promise<unknown> {
|
|
163
|
+
const url = this.apiUrl + endpoint;
|
|
164
|
+
const maxRetry = this.connOptions.maxRetry;
|
|
165
|
+
// `maxRetry` is the number of retries on top of the initial attempt, so we
|
|
166
|
+
// run up to `maxRetry + 1` total attempts. This matches the convention used
|
|
167
|
+
// by other agents-js plugins (e.g. lemonslice/runway) and ensures a single
|
|
168
|
+
// attempt still fires when callers configure `maxRetry: 0`.
|
|
169
|
+
for (let i = 0; i <= maxRetry; i++) {
|
|
170
|
+
try {
|
|
171
|
+
const response = await fetch(url, {
|
|
172
|
+
method: 'POST',
|
|
173
|
+
headers,
|
|
174
|
+
body: JSON.stringify(payload),
|
|
175
|
+
signal: AbortSignal.timeout(this.connOptions.timeoutMs),
|
|
176
|
+
});
|
|
177
|
+
if (!response.ok) {
|
|
178
|
+
const text = await response.text();
|
|
179
|
+
throw new APIStatusError({
|
|
180
|
+
message: `Server returned an error for ${url}: ${response.status}`,
|
|
181
|
+
options: { statusCode: response.status, body: { error: text } },
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
return await response.json();
|
|
185
|
+
} catch (e) {
|
|
186
|
+
if (e instanceof APIStatusError && !e.retryable) {
|
|
187
|
+
throw e;
|
|
188
|
+
}
|
|
189
|
+
this.#logger.warn(
|
|
190
|
+
{ error: String(e), url, attempt: i },
|
|
191
|
+
`API request to ${url} failed on attempt ${i}`,
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (i < maxRetry) {
|
|
196
|
+
await new Promise((resolve) => setTimeout(resolve, this.connOptions.retryIntervalMs));
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
throw new APIConnectionError({
|
|
200
|
+
message: `Failed to call LiveAvatar API after ${maxRetry + 1} attempts`,
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|