Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
Co-authored-by: lukasIO <[email protected]>
  • Loading branch information
nbsp and lukasIO committed May 17, 2024
1 parent d085134 commit e37a48c
Show file tree
Hide file tree
Showing 24 changed files with 1,315 additions and 220 deletions.
8 changes: 2 additions & 6 deletions agents/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,13 @@
"type": "module",
"scripts": {
"build": "tsc",
"lint": "eslint src",
"lint": "eslint -f unix \"src/**/*.ts\"",
"api:check": "api-extractor run --typescript-compiler-folder ../node_modules/typescript",
"api:update": "api-extractor run --local --typescript-compiler-folder ../node_modules/typescript --verbose"
},
"devDependencies": {
"@microsoft/api-extractor": "^7.35.0",
"@types/ws": "^8.5.10",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"typescript-eslint": "^7.4.0"
"@types/ws": "^8.5.10"
},
"peerDependencies": {
"typescript": "^5.0.0"
Expand Down
9 changes: 4 additions & 5 deletions agents/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
//
// SPDX-License-Identifier: Apache-2.0

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

type CliArgs = {
opts: WorkerOptions;
Expand Down
3 changes: 1 addition & 2 deletions agents/src/http_server.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
//
// SPDX-License-Identifier: Apache-2.0

import { createServer, ServerResponse, Server, IncomingMessage } from 'http';
import { type IncomingMessage, type Server, type ServerResponse, createServer } from 'http';

const healthCheck = async (res: ServerResponse) => {
res.writeHead(200);
Expand Down
8 changes: 5 additions & 3 deletions agents/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
//
// SPDX-License-Identifier: Apache-2.0
import * as cli from './cli.js';
import * as stt from './stt/index.js';
import * as tts from './tts/index.js';

export * from './vad.js';
export * from './plugin.js';
Expand All @@ -10,6 +13,5 @@ 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';

export { cli, stt, tts };
7 changes: 3 additions & 4 deletions agents/src/ipc/job_main.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
//
// SPDX-License-Identifier: Apache-2.0

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

export const runJob = (args: JobMainArgs): ChildProcess => {
return fork(__filename, [args.raw, args.entry, args.fallbackURL]);
Expand Down
25 changes: 15 additions & 10 deletions agents/src/ipc/job_process.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
//
// SPDX-License-Identifier: Apache-2.0

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

const START_TIMEOUT = 90 * 1000;
const PING_INTERVAL = 5 * 1000;
Expand All @@ -21,9 +26,9 @@ export class JobProcess {
args: JobMainArgs;
logger: Logger;
process?: ChildProcess;
startTimeout?: Timer;
pongTimeout?: Timer;
pingInterval?: Timer;
startTimeout?: ReturnType<typeof setTimeout>;
pongTimeout?: ReturnType<typeof setTimeout>;
pingInterval?: ReturnType<typeof setInterval>;

constructor(job: Job, acceptData: AcceptData, raw: string, fallbackURL: string) {
this.#job = job;
Expand Down
7 changes: 3 additions & 4 deletions agents/src/job_context.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
//
// SPDX-License-Identifier: Apache-2.0

import { Room, LocalParticipant, RemoteParticipant } from '@livekit/rtc-node';
import { Job } from '@livekit/protocol';
import { EventEmitter } from 'events';
import type { Job } from '@livekit/protocol';
import type { LocalParticipant, RemoteParticipant, Room } from '@livekit/rtc-node';
import type { EventEmitter } from 'events';

export class JobContext {
#job: Job;
Expand Down
5 changes: 2 additions & 3 deletions agents/src/job_request.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
//
// SPDX-License-Identifier: Apache-2.0

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

class AnsweredError extends Error {
constructor() {
Expand Down
3 changes: 1 addition & 2 deletions agents/src/log.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
//
// SPDX-License-Identifier: Apache-2.0

import pino from 'pino';
import { pino } from 'pino';

export const log = pino({
transport: {
Expand Down
7 changes: 3 additions & 4 deletions agents/src/stt/stream_adapter.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
//
// SPDX-License-Identifier: Apache-2.0

import type { AudioFrame } from '@livekit/rtc-node';
import { type AudioBuffer, mergeFrames } from '../utils.js';
import { VADEventType, type VADStream } from '../vad.js';
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.js';

export class StreamAdapterWrapper extends SpeechStream {
closed: boolean;
Expand Down
5 changes: 2 additions & 3 deletions agents/src/stt/stt.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
//
// SPDX-License-Identifier: Apache-2.0

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

export enum SpeechEventType {
START_OF_SPEECH = 0,
Expand Down
13 changes: 11 additions & 2 deletions agents/src/tts/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
//
// SPDX-License-Identifier: Apache-2.0
import { StreamAdapter, StreamAdapterWrapper } from './stream_adapter.js';
import {
SynthesisEvent,
SynthesisEventType,
SynthesizeStream,
type SynthesizedAudio,
TTS,
} from './tts.js';

export {
TTS,
SynthesisEvent,
SynthesisEventType,
SynthesizedAudio,
SynthesizeStream,
} from './tts.js';
export { StreamAdapter, StreamAdapterWrapper } from './stream_adapter.js';
StreamAdapter,
StreamAdapterWrapper,
};
7 changes: 3 additions & 4 deletions agents/src/tts/stream_adapter.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
//
// SPDX-License-Identifier: Apache-2.0

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

export class StreamAdapterWrapper extends SynthesizeStream {
closed: boolean;
Expand Down
3 changes: 1 addition & 2 deletions agents/src/tts/tts.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
//
// SPDX-License-Identifier: Apache-2.0

import { AudioFrame } from '@livekit/rtc-node';
import type { AudioFrame } from '@livekit/rtc-node';

export interface SynthesizedAudio {
text: string;
Expand Down
1 change: 0 additions & 1 deletion agents/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
//
// SPDX-License-Identifier: Apache-2.0

import { AudioFrame } from '@livekit/rtc-node';

export type AudioBuffer = AudioFrame[] | AudioFrame;
Expand Down
3 changes: 1 addition & 2 deletions agents/src/vad.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
//
// SPDX-License-Identifier: Apache-2.0

import { AudioFrame } from '@livekit/rtc-node';
import type { AudioFrame } from '@livekit/rtc-node';

export enum VADEventType {
START_OF_SPEECH = 1,
Expand Down
23 changes: 11 additions & 12 deletions agents/src/worker.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
//
// SPDX-License-Identifier: Apache-2.0

import os from 'os';
import { WebSocket } from 'ws';
import { AvailRes, JobRequest } from './job_request.js';
import {
type AvailabilityRequest,
type Job,
type JobAssignment,
JobType,
Job,
WorkerMessage,
ParticipantPermission,
ServerMessage,
AvailabilityRequest,
JobAssignment,
WorkerMessage,
} from '@livekit/protocol';
import { AcceptData } from './job_request.js';
import { EventEmitter } from 'events';
import { AccessToken } from 'livekit-server-sdk';
import os from 'os';
import { WebSocket } from 'ws';
import { HTTPServer } from './http_server.js';
import { JobProcess } from './ipc/job_process.js';
import { type AvailRes, JobRequest } from './job_request.js';
import type { AcceptData } from './job_request.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.js';

const MAX_RECONNECT_ATTEMPTS = 10;
const ASSIGNMENT_TIMEOUT = 15 * 1000;
Expand Down
5 changes: 1 addition & 4 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
"type": "module",
"scripts": {
"build": "tsc",
"lint": "eslint src"
},
"devDependencies": {
"@types/bun": "latest"
"lint": "eslint -f unix \"src/**/*.ts\""
},
"peerDependencies": {
"typescript": "^5.0.0"
Expand Down
3 changes: 1 addition & 2 deletions examples/src/minimal.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
//
// SPDX-License-Identifier: Apache-2.0

import { cli, JobContext, JobRequest, WorkerOptions } from '@livekit/agents';
import { type JobContext, type JobRequest, WorkerOptions, cli } from '@livekit/agents';
import { fileURLToPath } from 'url';

// your entry file *has* to include an exported function [entry].
Expand Down
3 changes: 1 addition & 2 deletions examples/src/tts.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
//
// SPDX-License-Identifier: Apache-2.0

import { cli, JobContext, JobRequest, log, WorkerOptions } from '@livekit/agents';
import { type JobContext, type JobRequest, WorkerOptions, cli, log } from '@livekit/agents';
import { TTS } from '@livekit/agents-plugin-elevenlabs';
import { AudioSource, LocalAudioTrack, TrackPublishOptions, TrackSource } from '@livekit/rtc-node';
import { fileURLToPath } from 'url';
Expand Down
16 changes: 16 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"build:plugins": "turbo run build --filter=@livekit/agents-plugin-*...",
"api:check": "turbo run api:check",
"api:update": "turbo run api:update",
"format:check": "prettier --check \"**/src/**/*.{ts,tsx,md,json}\"",
"format:write": "prettier --write \"**/src/**/*.{ts,tsx,md,json}\"",
"lint": "turbo lint",
"test": "vitest run",
"test:watch": "vitest"
Expand All @@ -16,6 +18,20 @@
"@changesets/cli": "^2.27.1",
"@livekit/changesets-changelog-github": "^0.0.4",
"@rushstack/heft": "^0.66.0",
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"eslint": "^8.56.0",
"eslint-config-next": "^14.1.0",
"eslint-config-prettier": "^8.10.0",
"eslint-config-standard": "^17.1.0",
"eslint-config-turbo": "^1.12.2",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-standard": "^5.0.0",
"eslint-plugin-tsdoc": "^0.2.17",
"prettier": "^3.2.5",
"turbo": "^1.13.3",
"typescript": "5.4.5",
Expand Down
8 changes: 2 additions & 6 deletions plugins/elevenlabs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,13 @@
"type": "module",
"scripts": {
"build": "tsc",
"lint": "eslint src",
"lint": "eslint -f unix \"src/**/*.{ts,js}\"",
"api:check": "api-extractor run --typescript-compiler-folder ../../node_modules/typescript",
"api:update": "api-extractor run --local --typescript-compiler-folder ../../node_modules/typescript --verbose"
},
"devDependencies": {
"@microsoft/api-extractor": "^7.35.0",
"@types/ws": "^8.5.10",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"typescript-eslint": "^7.4.0"
"@types/ws": "^8.5.10"
},
"peerDependencies": {
"typescript": "^5.0.0"
Expand Down
7 changes: 3 additions & 4 deletions plugins/elevenlabs/src/tts.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
//
// SPDX-License-Identifier: Apache-2.0

import { TTSModels } from './models.js';
import { log, tts } from '@livekit/agents';
import { RawData, WebSocket } from 'ws';
import { URL } from 'url';
import { AudioFrame } from '@livekit/rtc-node';
import { URL } from 'url';
import { type RawData, WebSocket } from 'ws';
import type { TTSModels } from './models.js';

type Voice = {
id: string;
Expand Down
Loading

0 comments on commit e37a48c

Please sign in to comment.