Skip to content

Commit

Permalink
Use pnpm instead of Bun
Browse files Browse the repository at this point in the history
  • Loading branch information
nbsp committed Apr 30, 2024
1 parent f6fb66f commit 2f95fa7
Show file tree
Hide file tree
Showing 25 changed files with 1,605 additions and 69 deletions.
34 changes: 25 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,42 @@ jobs:
- uses: actions/checkout@v4
- name: REUSE-3.0 compliance check
uses: fsfe/reuse-action@v3
- uses: oven-sh/setup-bun@v1
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm
- name: Install dependencies
run: pnpm install
- name: ESLint
run: |
bun install
cd agents
bun lint
pnpm lint
cd ../plugins/elevenlabs
bun lint
pnpm lint
build:
name: Build
runs-on: ubuntu-latest
needs: lint
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
- name: Bun build
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm
- name: Install dependencies
run: pnpm install
- name: pnpm build
run: |
bun install
cd agents
bun run build
pnpm build
cd ../plugins/elevenlabs
bun run build
pnpm build
4 changes: 2 additions & 2 deletions .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ Copyright: 2024 LiveKit, Inc.
License: Apache-2.0

# global project files
Files: package.json bun.lockb .prettierrc eslint.config.mjs
Files: .prettierrc eslint.config.mjs pnpm-lock.yaml pnpm-workspace.yaml
Copyright: 2024 LiveKit, Inc.
License: Apache-2.0

# sub-project files
Files: agents/package.json examples/package.json plugins/elevenlabs/package.json agents/tsconfig.json plugins/elevenlabs/tsconfig.json
Files: agents/package.json examples/package.json plugins/elevenlabs/package.json agents/tsconfig.json plugins/elevenlabs/tsconfig.json examples/tsconfig.json
Copyright: 2024 LiveKit, Inc.
License: Apache-2.0
13 changes: 2 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,15 @@ SPDX-License-Identifier: Apache-2.0

This is a Node port of the [LiveKit Agents framework](https://livekit.io/agents), originally written in Python.

## Development
This project builds to Node-compatible JavaScript, but is developed using the faster [Bun](https://bun.sh) JavaScript runtime. As a superset of Node, there are some caveats:

- Bun uses `package.json#workspaces` for monorepo handling, while pnpm uses `pnpm-workspace.yaml`. Using pnpm will therefore generate a new `node_modules/` for every subpackage.
- Running the `build` script invokes the [considerably faster](https://github-production-user-asset-6210df.s3.amazonaws.com/3084745/266451348-e65fa63c-99c7-4bcf-950b-e2fe9408a942.png) `Bun.build` bundler, as opposed to running `tsc`.
- Other incompatibilities which may be added to the project at any time

For this reason, while it should be possible to use npm, yarn, or pnpm with minor modifications to the builder, it is advised to install Bun.

## Building

This project depends on [`@livekit/rtc-node`](https://npmjs.com/package/@livekit/rtc-node), which itself depends on `libstdc++` version 6 being in PATH.

Install the project dependencies and run the build script:
```sh
$ bun install
$ pnpm install
$ cd agents
$ bun run build
$ pnpm build
```

Your output will be in the `dist/` directory.
Expand Down
6 changes: 3 additions & 3 deletions agents/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
//
// SPDX-License-Identifier: Apache-2.0

import { version } from '.';
import { version } from './version.js';
import { Option, Command } from 'commander';
import { WorkerOptions, Worker } from './worker';
import { WorkerOptions, Worker } from './worker.js';
import { EventEmitter } from 'events';
import { log } from './log';
import { log } from './log.js';

type CliArgs = {
opts: WorkerOptions;
Expand Down
22 changes: 11 additions & 11 deletions agents/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
//
// SPDX-License-Identifier: Apache-2.0

export * from './vad';
export * from './plugin';
export * from './version';
export * from './job_context';
export * from './job_request';
export * from './worker';
export * from './utils';
export * from './log';
export * as cli from './cli';
export * as stt from './stt';
export * as tts from './tts';
export * from './vad.js';
export * from './plugin.js';
export * from './version.js';
export * from './job_context.js';
export * from './job_request.js';
export * from './worker.js';
export * from './utils.js';
export * from './log.js';
export * as cli from './cli.js';
export * as stt from './stt/index.js';
export * as tts from './tts/index.js';
6 changes: 3 additions & 3 deletions agents/src/ipc/job_main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
//
// SPDX-License-Identifier: Apache-2.0

import { IPC_MESSAGE, JobMainArgs, Message, Ping } from './protocol';
import { IPC_MESSAGE, JobMainArgs, Message, Ping } from './protocol.js';
import { Room } from '@livekit/rtc-node';
import { EventEmitter, once } from 'events';
import { JobContext } from '../job_context';
import { log } from '../log';
import { JobContext } from '../job_context.js';
import { log } from '../log.js';
import { ChildProcess, fork } from 'child_process';
import { JobAssignment, ServerMessage } from '@livekit/protocol';

Expand Down
8 changes: 4 additions & 4 deletions agents/src/ipc/job_process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
// SPDX-License-Identifier: Apache-2.0

import { Job } from '@livekit/protocol';
import { IPC_MESSAGE, JobMainArgs, Message, Pong, StartJobResponse } from './protocol';
import { runJob } from './job_main';
import { IPC_MESSAGE, JobMainArgs, Message, Pong, StartJobResponse } from './protocol.js';
import { runJob } from './job_main.js';
import { once } from 'events';
import { log } from '../log';
import { log } from '../log.js';
import { Logger } from 'pino';
import { AcceptData } from '../job_request';
import { AcceptData } from '../job_request.js';
import { ChildProcess } from 'child_process';

const START_TIMEOUT = 90 * 1000;
Expand Down
2 changes: 1 addition & 1 deletion agents/src/job_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SPDX-License-Identifier: Apache-2.0

import { Job, ParticipantInfo, Room } from '@livekit/protocol';
import { log } from './log';
import { log } from './log.js';
import { EventEmitter } from 'events';

class AnsweredError extends Error {
Expand Down
4 changes: 2 additions & 2 deletions agents/src/stt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
//
// SPDX-License-Identifier: Apache-2.0

export { STT, SpeechEvent, SpeechEventType, SpeechStream } from './stt';
export { StreamAdapter, StreamAdapterWrapper } from './stream_adapter';
export { STT, SpeechEvent, SpeechEventType, SpeechStream } from './stt.js';
export { StreamAdapter, StreamAdapterWrapper } from './stream_adapter.js';
6 changes: 3 additions & 3 deletions agents/src/stt/stream_adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
//
// SPDX-License-Identifier: Apache-2.0

import { STT, SpeechEvent, SpeechEventType, SpeechStream } from './stt';
import { VADEventType, VADStream } from '../vad';
import { STT, SpeechEvent, SpeechEventType, SpeechStream } from './stt.js';
import { VADEventType, VADStream } from '../vad.js';
import { AudioFrame } from '@livekit/rtc-node';
import { AudioBuffer, mergeFrames } from '../utils';
import { AudioBuffer, mergeFrames } from '../utils.js';

export class StreamAdapterWrapper extends SpeechStream {
closed: boolean;
Expand Down
2 changes: 1 addition & 1 deletion agents/src/stt/stt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SPDX-License-Identifier: Apache-2.0

import { AudioFrame } from '@livekit/rtc-node';
import { AudioBuffer } from '../utils';
import { AudioBuffer } from '../utils.js';

export enum SpeechEventType {
START_OF_SPEECH = 0,
Expand Down
10 changes: 8 additions & 2 deletions agents/src/tts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,11 @@
//
// SPDX-License-Identifier: Apache-2.0

export { TTS, SynthesisEvent, SynthesisEventType, SynthesizedAudio, SynthesizeStream } from './tts';
export { StreamAdapter, StreamAdapterWrapper } from './stream_adapter';
export {
TTS,
SynthesisEvent,
SynthesisEventType,
SynthesizedAudio,
SynthesizeStream,
} from './tts.js';
export { StreamAdapter, StreamAdapterWrapper } from './stream_adapter.js';
10 changes: 8 additions & 2 deletions agents/src/tts/stream_adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
//
// SPDX-License-Identifier: Apache-2.0

import { TTS, SynthesisEvent, SynthesisEventType, SynthesizedAudio, SynthesizeStream } from './tts';
import { SentenceStream, SentenceTokenizer } from '../tokenize';
import {
TTS,
SynthesisEvent,
SynthesisEventType,
SynthesizedAudio,
SynthesizeStream,
} from './tts.js';
import { SentenceStream, SentenceTokenizer } from '../tokenize.js';

export class StreamAdapterWrapper extends SynthesizeStream {
closed: boolean;
Expand Down
12 changes: 6 additions & 6 deletions agents/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import os from 'os';
import { WebSocket } from 'ws';
import { AvailRes, JobRequest } from './job_request';
import { AvailRes, JobRequest } from './job_request.js';
import {
JobType,
Job,
Expand All @@ -14,13 +14,13 @@ import {
AvailabilityRequest,
JobAssignment,
} from '@livekit/protocol';
import { AcceptData } from './job_request';
import { HTTPServer } from './http_server';
import { log } from './log';
import { version } from './version';
import { AcceptData } from './job_request.js';
import { HTTPServer } from './http_server.js';
import { log } from './log.js';
import { version } from './version.js';
import { AccessToken } from 'livekit-server-sdk';
import { EventEmitter } from 'events';
import { JobProcess } from './ipc/job_process';
import { JobProcess } from './ipc/job_process.js';

const MAX_RECONNECT_ATTEMPTS = 10;
const ASSIGNMENT_TIMEOUT = 15 * 1000;
Expand Down
Binary file removed bun.lockb
Binary file not shown.
4 changes: 4 additions & 0 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
"private": true,
"name": "livekit-agents-examples",
"type": "module",
"scripts": {
"build": "tsc",
"lint": "eslint src"
},
"devDependencies": {
"@types/bun": "latest"
},
Expand Down
4 changes: 2 additions & 2 deletions examples/minimal.ts → examples/src/minimal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { fileURLToPath } from 'url';
// your entry file *has* to include an exported function [entry].
// this file will be imported from inside the library, and this function
// will be called.
export const entry = async (_: JobContext) => {
export const entry = async (job: JobContext) => {
console.log('starting voice assistant...');

job;
// etc
};

Expand Down
File renamed without changes.
15 changes: 15 additions & 0 deletions examples/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"lib": ["ESNext"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"moduleResolution": "node",
"allowJs": true,
"strict": true,
"skipLibCheck": true,
"esModuleInterop": true,
"outDir": "dist"
},
"include": ["**/*.ts"]
}
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

in {
devShell = with pkgs; mkShell {
nativeBuildInputs = [ bun reuse ];
nativeBuildInputs = [ nodejs nodePackages.pnpm reuse ];
LD_LIBRARY_PATH = "${pkgs.stdenv.cc.cc.lib}/lib/";
};
}
Expand Down
4 changes: 0 additions & 4 deletions package.json

This file was deleted.

2 changes: 1 addition & 1 deletion plugins/elevenlabs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
//
// SPDX-License-Identifier: Apache-2.0

export * from './tts';
export * from './tts.js';
2 changes: 1 addition & 1 deletion plugins/elevenlabs/src/tts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: Apache-2.0

import { TTSModels } from './models';
import { TTSModels } from './models.js';
import { log, tts } from '@livekit/agents';
import { RawData, WebSocket } from 'ws';
import { URL } from 'url';
Expand Down
Loading

0 comments on commit 2f95fa7

Please sign in to comment.