@livekit/agents-plugin-lemonslice 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 +72 -0
- package/dist/avatar.cjs +222 -0
- package/dist/avatar.cjs.map +1 -0
- package/dist/avatar.d.cts +135 -0
- package/dist/avatar.d.ts +135 -0
- package/dist/avatar.d.ts.map +1 -0
- package/dist/avatar.js +204 -0
- package/dist/avatar.js.map +1 -0
- package/dist/avatar.test.cjs +128 -0
- package/dist/avatar.test.cjs.map +1 -0
- package/dist/avatar.test.d.cts +2 -0
- package/dist/avatar.test.d.ts +2 -0
- package/dist/avatar.test.d.ts.map +1 -0
- package/dist/avatar.test.js +127 -0
- package/dist/avatar.test.js.map +1 -0
- package/dist/index.cjs +34 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -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 +51 -0
- package/src/avatar.test.ts +163 -0
- package/src/avatar.ts +338 -0
- package/src/index.ts +18 -0
- package/src/log.ts +7 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/avatar.test.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2026 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { initializeLogger, voice } from '@livekit/agents';\nimport { type Room, TrackKind } from '@livekit/rtc-node';\nimport { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';\nimport { AvatarSession } from './avatar.js';\n\ntype DataStreamAudioOutputInternals = {\n waitPlaybackStart: boolean;\n};\n\ndescribe('LemonSlice AvatarSession', () => {\n beforeEach(() => {\n initializeLogger({ pretty: false });\n global.fetch = vi.fn();\n });\n\n afterEach(() => {\n vi.restoreAllMocks();\n voice.DataStreamAudioOutput._playbackFinishedRpcRegistered = false;\n voice.DataStreamAudioOutput._playbackFinishedHandlers = {};\n voice.DataStreamAudioOutput._playbackStartedRpcRegistered = false;\n voice.DataStreamAudioOutput._playbackStartedHandlers = {};\n });\n\n it('merges extraPayload into the session creation request body', async () => {\n const mockFetch = vi.mocked(fetch);\n mockFetch.mockResolvedValue({\n ok: true,\n json: async () => ({ session_id: 'test-session-id' }),\n } as Response);\n\n const avatar = new AvatarSession({\n apiKey: 'test-api-key',\n agentImageUrl: 'https://example.com/avatar.png',\n extraPayload: {\n aspect_ratio: '9x16',\n },\n });\n\n await (\n avatar as unknown as {\n startAgent(livekitUrl: string, livekitToken: string): Promise<void>;\n }\n ).startAgent('wss://livekit.example.com', 'livekit-token');\n\n expect(mockFetch).toHaveBeenCalledTimes(1);\n expect(mockFetch).toHaveBeenCalledWith(\n 'https://lemonslice.com/api/liveai/sessions',\n expect.objectContaining({\n method: 'POST',\n body: JSON.stringify({\n transport_type: 'livekit',\n properties: {\n livekit_url: 'wss://livekit.example.com',\n livekit_token: 'livekit-token',\n },\n agent_image_url: 'https://example.com/avatar.png',\n aspect_ratio: '9x16',\n }),\n }),\n );\n });\n\n it('keeps the request body unchanged when extraPayload is omitted', async () => {\n const mockFetch = vi.mocked(fetch);\n mockFetch.mockResolvedValue({\n ok: true,\n json: async () => ({ session_id: 'test-session-id' }),\n } as Response);\n\n const avatar = new AvatarSession({\n apiKey: 'test-api-key',\n agentImageUrl: 'https://example.com/avatar.png',\n });\n\n await (\n avatar as unknown as {\n startAgent(livekitUrl: string, livekitToken: string): Promise<void>;\n }\n ).startAgent('wss://livekit.example.com', 'livekit-token');\n\n const requestInit = mockFetch.mock.calls[0]?.[1];\n const body = JSON.parse(String(requestInit?.body));\n\n expect(body).toEqual({\n transport_type: 'livekit',\n properties: {\n livekit_url: 'wss://livekit.example.com',\n livekit_token: 'livekit-token',\n },\n agent_image_url: 'https://example.com/avatar.png',\n });\n expect(body).not.toHaveProperty('aspect_ratio');\n });\n\n it('calls base AvatarSession.start first', async () => {\n const sentinel = new Error('super-start-called');\n const superStartSpy = vi\n .spyOn(voice.AvatarSession.prototype, 'start')\n .mockRejectedValue(sentinel);\n\n const avatar = new AvatarSession({\n apiKey: 'test-api-key',\n agentImageUrl: 'https://example.com/avatar.png',\n });\n\n await expect(\n avatar.start(\n { _started: false, output: { audio: null } } as unknown as voice.AgentSession,\n {} as unknown as Room,\n ),\n ).rejects.toThrow('super-start-called');\n expect(superStartSpy).toHaveBeenCalledTimes(1);\n });\n\n it('configures DataStreamAudioOutput to wait for remote playback started', async () => {\n vi.spyOn(voice.AvatarSession.prototype, 'start').mockResolvedValue(undefined);\n\n const avatar = new AvatarSession({\n apiKey: 'test-api-key',\n agentImageUrl: 'https://example.com/avatar.png',\n });\n vi.spyOn(\n avatar as unknown as {\n startAgent(livekitUrl: string, livekitToken: string): Promise<string>;\n },\n 'startAgent',\n ).mockResolvedValue('test-session-id');\n\n const remoteParticipant = {\n identity: 'lemonslice-avatar-agent',\n trackPublications: new Map([['video', { kind: TrackKind.KIND_VIDEO }]]),\n };\n const room = {\n name: 'test-room',\n isConnected: true,\n localParticipant: {\n identity: 'local-agent',\n registerRpcMethod: vi.fn(),\n },\n remoteParticipants: new Map([[remoteParticipant.identity, remoteParticipant]]),\n on: vi.fn(),\n off: vi.fn(),\n };\n const agentSession = {\n _started: false,\n output: { audio: null },\n } as unknown as voice.AgentSession;\n\n const sessionId = await avatar.start(agentSession, room as unknown as Room, {\n livekitUrl: 'wss://livekit.example.com',\n livekitApiKey: 'livekit-api-key',\n livekitApiSecret: 'livekit-api-secret',\n });\n\n expect(sessionId).toBe('test-session-id');\n const audioOutput = agentSession.output.audio;\n expect(audioOutput).toBeInstanceOf(voice.DataStreamAudioOutput);\n expect((audioOutput as unknown as DataStreamAudioOutputIn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AM,oBAAoB;AAAA,MACxB,UAAU;AAAA,MACV,mBAAmB,oBAAI,IAAI,CAAC,CAAC,SAAS,EAAE,MAAM,UAAU,WAAW,CAAC,CAAC,CAAC;AAAA,IACxE;AACA,UAAM,OAAO;AAAA,MACX,MAAM;AAAA,MACN,aAAa;AAAA,MACb,kBAAkB;AAAA,QAChB,UAAU;AAAA,QACV,mBAAmB,GAAG,GAAG;AAAA,MAC3B;AAAA,MACA,oBAAoB,oBAAI,IAAI,CAAC,CAAC,kBAAkB,UAAU,iBAAiB,CAAC,CAAC;AAAA,MAC7E,IAAI,GAAG,GAAG;AAAA,MACV,KAAK,GAAG,GAAG;AAAA,IACb;AACA,UAAM,eAAe;AAAA,MACnB,UAAU;AAAA,MACV,QAAQ,EAAE,OAAO,KAAK;AAAA,IACxB;AAEA,UAAM,YAAY,MAAM,OAAO,MAAM,cAAc,MAAyB;AAAA,MAC1E,YAAY;AAAA,MACZ,eAAe;AAAA,MACf,kBAAkB;AAAA,IACpB,CAAC;AAED,WAAO,SAAS,EAAE,KAAK,iBAAiB;AACxC,UAAM,cAAc,aAAa,OAAO;AACxC,WAAO,WAAW,EAAE,eAAe,MAAM,qBAAqB;AAC9D,WAAQ,YAA0D,iBAAiB,EAAE,KAAK,IAAI;AAAA,EAChG,CAAC;AACH,CAAC;","names":[]}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var index_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(index_exports);
|
|
18
|
+
var import_agents = require("@livekit/agents");
|
|
19
|
+
__reExport(index_exports, require("./avatar.cjs"), module.exports);
|
|
20
|
+
class LemonSlicePlugin extends import_agents.Plugin {
|
|
21
|
+
constructor() {
|
|
22
|
+
super({
|
|
23
|
+
title: "lemonslice",
|
|
24
|
+
version: "0.0.0-next-20260624041820",
|
|
25
|
+
package: "@livekit/agents-plugin-lemonslice"
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
import_agents.Plugin.registerPlugin(new LemonSlicePlugin());
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 && (module.exports = {
|
|
32
|
+
...require("./avatar.cjs")
|
|
33
|
+
});
|
|
34
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { Plugin } from '@livekit/agents';\n\nexport * from './avatar.js';\n\nclass LemonSlicePlugin extends Plugin {\n constructor() {\n super({\n title: 'lemonslice',\n version: __PACKAGE_VERSION__,\n package: __PACKAGE_NAME__,\n });\n }\n}\n\nPlugin.registerPlugin(new LemonSlicePlugin());\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAGA,oBAAuB;AAEvB,0BAAc,wBALd;AAOA,MAAM,yBAAyB,qBAAO;AAAA,EACpC,cAAc;AACZ,UAAM;AAAA,MACJ,OAAO;AAAA,MACP,SAAS;AAAA,MACT,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AACF;AAEA,qBAAO,eAAe,IAAI,iBAAiB,CAAC;","names":[]}
|
package/dist/index.d.cts
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,cAAc,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Plugin } from "@livekit/agents";
|
|
2
|
+
export * from "./avatar.js";
|
|
3
|
+
class LemonSlicePlugin extends Plugin {
|
|
4
|
+
constructor() {
|
|
5
|
+
super({
|
|
6
|
+
title: "lemonslice",
|
|
7
|
+
version: "0.0.0-next-20260624041820",
|
|
8
|
+
package: "@livekit/agents-plugin-lemonslice"
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
Plugin.registerPlugin(new LemonSlicePlugin());
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { Plugin } from '@livekit/agents';\n\nexport * from './avatar.js';\n\nclass LemonSlicePlugin extends Plugin {\n constructor() {\n super({\n title: 'lemonslice',\n version: __PACKAGE_VERSION__,\n package: __PACKAGE_NAME__,\n });\n }\n}\n\nPlugin.registerPlugin(new LemonSlicePlugin());\n"],"mappings":"AAGA,SAAS,cAAc;AAEvB,cAAc;AAEd,MAAM,yBAAyB,OAAO;AAAA,EACpC,cAAc;AACZ,UAAM;AAAA,MACJ,OAAO;AAAA,MACP,SAAS;AAAA,MACT,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AACF;AAEA,OAAO,eAAe,IAAI,iBAAiB,CAAC;","names":[]}
|
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: "lemonslice" });
|
|
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: 2025 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: 'lemonslice' });\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: 2025 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: 'lemonslice' });\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,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@livekit/agents-plugin-lemonslice",
|
|
3
|
+
"version": "0.0.0-next-20260624041820",
|
|
4
|
+
"description": "LemonSlice 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
|
+
"pino": "^8.19.0",
|
|
31
|
+
"tsup": "^8.3.5",
|
|
32
|
+
"typescript": "^5.0.0",
|
|
33
|
+
"@livekit/agents": "0.0.0-next-20260624041820"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"livekit-server-sdk": "^2.13.3"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"@livekit/rtc-node": "^0.13.29",
|
|
40
|
+
"@livekit/agents": "0.0.0-next-20260624041820"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "tsup --onSuccess \"pnpm build:types\"",
|
|
44
|
+
"build:types": "tsc --declaration --emitDeclarationOnly && node ../../scripts/copyDeclarationOutput.js",
|
|
45
|
+
"clean": "rm -rf dist",
|
|
46
|
+
"clean:build": "pnpm clean && pnpm build",
|
|
47
|
+
"lint": "eslint -f unix \"src/**/*.{ts,js}\"",
|
|
48
|
+
"api:check": "api-extractor run --typescript-compiler-folder ../../node_modules/typescript",
|
|
49
|
+
"api:update": "api-extractor run --local --typescript-compiler-folder ../../node_modules/typescript --verbose"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 LiveKit, Inc.
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
import { initializeLogger, voice } from '@livekit/agents';
|
|
5
|
+
import { type Room, TrackKind } from '@livekit/rtc-node';
|
|
6
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
7
|
+
import { AvatarSession } from './avatar.js';
|
|
8
|
+
|
|
9
|
+
type DataStreamAudioOutputInternals = {
|
|
10
|
+
waitPlaybackStart: boolean;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
describe('LemonSlice AvatarSession', () => {
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
initializeLogger({ pretty: false });
|
|
16
|
+
global.fetch = vi.fn();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
afterEach(() => {
|
|
20
|
+
vi.restoreAllMocks();
|
|
21
|
+
voice.DataStreamAudioOutput._playbackFinishedRpcRegistered = false;
|
|
22
|
+
voice.DataStreamAudioOutput._playbackFinishedHandlers = {};
|
|
23
|
+
voice.DataStreamAudioOutput._playbackStartedRpcRegistered = false;
|
|
24
|
+
voice.DataStreamAudioOutput._playbackStartedHandlers = {};
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('merges extraPayload into the session creation request body', async () => {
|
|
28
|
+
const mockFetch = vi.mocked(fetch);
|
|
29
|
+
mockFetch.mockResolvedValue({
|
|
30
|
+
ok: true,
|
|
31
|
+
json: async () => ({ session_id: 'test-session-id' }),
|
|
32
|
+
} as Response);
|
|
33
|
+
|
|
34
|
+
const avatar = new AvatarSession({
|
|
35
|
+
apiKey: 'test-api-key',
|
|
36
|
+
agentImageUrl: 'https://example.com/avatar.png',
|
|
37
|
+
extraPayload: {
|
|
38
|
+
aspect_ratio: '9x16',
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
await (
|
|
43
|
+
avatar as unknown as {
|
|
44
|
+
startAgent(livekitUrl: string, livekitToken: string): Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
).startAgent('wss://livekit.example.com', 'livekit-token');
|
|
47
|
+
|
|
48
|
+
expect(mockFetch).toHaveBeenCalledTimes(1);
|
|
49
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
50
|
+
'https://lemonslice.com/api/liveai/sessions',
|
|
51
|
+
expect.objectContaining({
|
|
52
|
+
method: 'POST',
|
|
53
|
+
body: JSON.stringify({
|
|
54
|
+
transport_type: 'livekit',
|
|
55
|
+
properties: {
|
|
56
|
+
livekit_url: 'wss://livekit.example.com',
|
|
57
|
+
livekit_token: 'livekit-token',
|
|
58
|
+
},
|
|
59
|
+
agent_image_url: 'https://example.com/avatar.png',
|
|
60
|
+
aspect_ratio: '9x16',
|
|
61
|
+
}),
|
|
62
|
+
}),
|
|
63
|
+
);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('keeps the request body unchanged when extraPayload is omitted', async () => {
|
|
67
|
+
const mockFetch = vi.mocked(fetch);
|
|
68
|
+
mockFetch.mockResolvedValue({
|
|
69
|
+
ok: true,
|
|
70
|
+
json: async () => ({ session_id: 'test-session-id' }),
|
|
71
|
+
} as Response);
|
|
72
|
+
|
|
73
|
+
const avatar = new AvatarSession({
|
|
74
|
+
apiKey: 'test-api-key',
|
|
75
|
+
agentImageUrl: 'https://example.com/avatar.png',
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
await (
|
|
79
|
+
avatar as unknown as {
|
|
80
|
+
startAgent(livekitUrl: string, livekitToken: string): Promise<void>;
|
|
81
|
+
}
|
|
82
|
+
).startAgent('wss://livekit.example.com', 'livekit-token');
|
|
83
|
+
|
|
84
|
+
const requestInit = mockFetch.mock.calls[0]?.[1];
|
|
85
|
+
const body = JSON.parse(String(requestInit?.body));
|
|
86
|
+
|
|
87
|
+
expect(body).toEqual({
|
|
88
|
+
transport_type: 'livekit',
|
|
89
|
+
properties: {
|
|
90
|
+
livekit_url: 'wss://livekit.example.com',
|
|
91
|
+
livekit_token: 'livekit-token',
|
|
92
|
+
},
|
|
93
|
+
agent_image_url: 'https://example.com/avatar.png',
|
|
94
|
+
});
|
|
95
|
+
expect(body).not.toHaveProperty('aspect_ratio');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('calls base AvatarSession.start first', async () => {
|
|
99
|
+
const sentinel = new Error('super-start-called');
|
|
100
|
+
const superStartSpy = vi
|
|
101
|
+
.spyOn(voice.AvatarSession.prototype, 'start')
|
|
102
|
+
.mockRejectedValue(sentinel);
|
|
103
|
+
|
|
104
|
+
const avatar = new AvatarSession({
|
|
105
|
+
apiKey: 'test-api-key',
|
|
106
|
+
agentImageUrl: 'https://example.com/avatar.png',
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
await expect(
|
|
110
|
+
avatar.start(
|
|
111
|
+
{ _started: false, output: { audio: null } } as unknown as voice.AgentSession,
|
|
112
|
+
{} as unknown as Room,
|
|
113
|
+
),
|
|
114
|
+
).rejects.toThrow('super-start-called');
|
|
115
|
+
expect(superStartSpy).toHaveBeenCalledTimes(1);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('configures DataStreamAudioOutput to wait for remote playback started', async () => {
|
|
119
|
+
vi.spyOn(voice.AvatarSession.prototype, 'start').mockResolvedValue(undefined);
|
|
120
|
+
|
|
121
|
+
const avatar = new AvatarSession({
|
|
122
|
+
apiKey: 'test-api-key',
|
|
123
|
+
agentImageUrl: 'https://example.com/avatar.png',
|
|
124
|
+
});
|
|
125
|
+
vi.spyOn(
|
|
126
|
+
avatar as unknown as {
|
|
127
|
+
startAgent(livekitUrl: string, livekitToken: string): Promise<string>;
|
|
128
|
+
},
|
|
129
|
+
'startAgent',
|
|
130
|
+
).mockResolvedValue('test-session-id');
|
|
131
|
+
|
|
132
|
+
const remoteParticipant = {
|
|
133
|
+
identity: 'lemonslice-avatar-agent',
|
|
134
|
+
trackPublications: new Map([['video', { kind: TrackKind.KIND_VIDEO }]]),
|
|
135
|
+
};
|
|
136
|
+
const room = {
|
|
137
|
+
name: 'test-room',
|
|
138
|
+
isConnected: true,
|
|
139
|
+
localParticipant: {
|
|
140
|
+
identity: 'local-agent',
|
|
141
|
+
registerRpcMethod: vi.fn(),
|
|
142
|
+
},
|
|
143
|
+
remoteParticipants: new Map([[remoteParticipant.identity, remoteParticipant]]),
|
|
144
|
+
on: vi.fn(),
|
|
145
|
+
off: vi.fn(),
|
|
146
|
+
};
|
|
147
|
+
const agentSession = {
|
|
148
|
+
_started: false,
|
|
149
|
+
output: { audio: null },
|
|
150
|
+
} as unknown as voice.AgentSession;
|
|
151
|
+
|
|
152
|
+
const sessionId = await avatar.start(agentSession, room as unknown as Room, {
|
|
153
|
+
livekitUrl: 'wss://livekit.example.com',
|
|
154
|
+
livekitApiKey: 'livekit-api-key',
|
|
155
|
+
livekitApiSecret: 'livekit-api-secret',
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
expect(sessionId).toBe('test-session-id');
|
|
159
|
+
const audioOutput = agentSession.output.audio;
|
|
160
|
+
expect(audioOutput).toBeInstanceOf(voice.DataStreamAudioOutput);
|
|
161
|
+
expect((audioOutput as unknown as DataStreamAudioOutputInternals).waitPlaybackStart).toBe(true);
|
|
162
|
+
});
|
|
163
|
+
});
|