🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

@livekit/agents-plugin-openai

Package Overview
Dependencies
Maintainers
0
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@livekit/agents-plugin-openai - npm Package Compare versions

Comparing version

to
0.3.1

11

CHANGELOG.md
# @livekit/agents-plugin-openai
## 0.3.1
### Patch Changes
- implement session close - [#79](https://github.com/livekit/agents-js/pull/79) ([@nbsp](https://github.com/nbsp))
- make sure rejects return errors, not string - [#84](https://github.com/livekit/agents-js/pull/84) ([@nbsp](https://github.com/nbsp))
- Updated dependencies [[`d3db7cf19c696f611b5717ff8d510b2f910da712`](https://github.com/livekit/agents-js/commit/d3db7cf19c696f611b5717ff8d510b2f910da712), [`c0cce8a0f71cd8def7052917d8a6479e06178447`](https://github.com/livekit/agents-js/commit/c0cce8a0f71cd8def7052917d8a6479e06178447), [`e748aa4f7be76361c5fcafb03bdb760314b29a9f`](https://github.com/livekit/agents-js/commit/e748aa4f7be76361c5fcafb03bdb760314b29a9f), [`b35952ca243fecb087c898b670f5db0eaa1949bf`](https://github.com/livekit/agents-js/commit/b35952ca243fecb087c898b670f5db0eaa1949bf), [`4edacb8ba7dbbdd060dfedffe3116f1af4739b52`](https://github.com/livekit/agents-js/commit/4edacb8ba7dbbdd060dfedffe3116f1af4739b52)]:
- @livekit/agents@0.3.1
## 0.3.0

@@ -4,0 +15,0 @@

19

dist/realtime/api_proto.d.ts

@@ -38,4 +38,2 @@ export declare const SAMPLE_RATE = 24000;

silence_duration_ms?: number;
} | {
type: 'none';
};

@@ -105,12 +103,13 @@ export type InputAudioTranscription = {

modalities: ['text', 'audio'] | ['text'];
instructions?: string;
instructions: string;
voice: Voice;
input_audio_format: AudioFormat;
output_audio_format: AudioFormat;
input_audio_transcription?: InputAudioTranscription;
turn_detection: TurnDetectionType;
input_audio_transcription: InputAudioTranscription | null;
turn_detection: TurnDetectionType | null;
tools: Tool[];
tool_choice: ToolChoice;
temperature: number;
max_response_output_tokens: number | null;
max_response_output_tokens: number | 'inf';
expires_at: number;
}

@@ -158,8 +157,8 @@ export interface ConversationResource {

output_audio_format: AudioFormat;
input_audio_transcription?: InputAudioTranscription;
turn_detection: TurnDetectionType;
input_audio_transcription: InputAudioTranscription | null;
turn_detection: TurnDetectionType | null;
tools: Tool[];
tool_choice: ToolChoice;
temperature: number;
max_response_output_tokens: number;
max_response_output_tokens: number | 'inf';
}>;

@@ -223,3 +222,3 @@ }

temperature: number;
max_response_output_tokens: number;
max_output_tokens: number | 'inf';
}>;

@@ -226,0 +225,0 @@ }

@@ -7,10 +7,10 @@ import { AsyncIterableQueue, Future } from '@livekit/agents';

modalities: ['text', 'audio'] | ['text'];
instructions?: string;
instructions: string;
voice: api_proto.Voice;
inputAudioFormat: api_proto.AudioFormat;
outputAudioFormat: api_proto.AudioFormat;
inputAudioTranscription?: api_proto.InputAudioTranscription;
turnDetection: api_proto.TurnDetectionType;
inputAudioTranscription: api_proto.InputAudioTranscription | null;
turnDetection: api_proto.TurnDetectionType | null;
temperature: number;
maxResponseOutputTokens?: number;
maxResponseOutputTokens: number;
model: api_proto.Model;

@@ -118,4 +118,4 @@ apiKey: string;

outputAudioFormat?: api_proto.AudioFormat;
inputAudioTranscription?: api_proto.InputAudioTranscription;
turnDetection?: api_proto.TurnDetectionType;
inputAudioTranscription?: api_proto.InputAudioTranscription | null;
turnDetection?: api_proto.TurnDetectionType | null;
temperature?: number;

@@ -134,2 +134,3 @@ maxResponseOutputTokens?: number;

get response(): Response;
get expiration(): number;
queueMsg(command: api_proto.ClientEvent): void;

@@ -142,4 +143,4 @@ sessionUpdate({ modalities, instructions, voice, inputAudioFormat, outputAudioFormat, inputAudioTranscription, turnDetection, temperature, maxResponseOutputTokens, toolChoice, }: {

outputAudioFormat?: api_proto.AudioFormat;
inputAudioTranscription?: api_proto.InputAudioTranscription;
turnDetection?: api_proto.TurnDetectionType;
inputAudioTranscription?: api_proto.InputAudioTranscription | null;
turnDetection?: api_proto.TurnDetectionType | null;
temperature?: number;

@@ -146,0 +147,0 @@ maxResponseOutputTokens?: number;

@@ -12,3 +12,3 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {

};
var _InputAudioBuffer_session, _ConversationItem_session, _Conversation_session, _Response_session, _RealtimeModel_defaultOpts, _RealtimeModel_sessions, _RealtimeSession_instances, _RealtimeSession_fncCtx, _RealtimeSession_opts, _RealtimeSession_pendingResponses, _RealtimeSession_sessionId, _RealtimeSession_ws, _RealtimeSession_logger, _RealtimeSession_task, _RealtimeSession_closing, _RealtimeSession_sendQueue, _RealtimeSession_loggableEvent, _RealtimeSession_start, _RealtimeSession_getContent, _RealtimeSession_handleError, _RealtimeSession_handleSessionCreated, _RealtimeSession_handleSessionUpdated, _RealtimeSession_handleConversationCreated, _RealtimeSession_handleInputAudioBufferCommitted, _RealtimeSession_handleInputAudioBufferCleared, _RealtimeSession_handleInputAudioBufferSpeechStarted, _RealtimeSession_handleInputAudioBufferSpeechStopped, _RealtimeSession_handleConversationItemCreated, _RealtimeSession_handleConversationItemInputAudioTranscriptionCompleted, _RealtimeSession_handleConversationItemInputAudioTranscriptionFailed, _RealtimeSession_handleConversationItemTruncated, _RealtimeSession_handleConversationItemDeleted, _RealtimeSession_handleResponseCreated, _RealtimeSession_handleResponseDone, _RealtimeSession_handleResponseOutputItemAdded, _RealtimeSession_handleResponseOutputItemDone, _RealtimeSession_handleResponseContentPartAdded, _RealtimeSession_handleResponseContentPartDone, _RealtimeSession_handleResponseTextDelta, _RealtimeSession_handleResponseTextDone, _RealtimeSession_handleResponseAudioTranscriptDelta, _RealtimeSession_handleResponseAudioTranscriptDone, _RealtimeSession_handleResponseAudioDelta, _RealtimeSession_handleResponseAudioDone, _RealtimeSession_handleResponseFunctionCallArgumentsDelta, _RealtimeSession_handleResponseFunctionCallArgumentsDone, _RealtimeSession_handleRateLimitsUpdated;
var _InputAudioBuffer_session, _ConversationItem_session, _Conversation_session, _Response_session, _RealtimeModel_defaultOpts, _RealtimeModel_sessions, _RealtimeSession_instances, _RealtimeSession_fncCtx, _RealtimeSession_opts, _RealtimeSession_pendingResponses, _RealtimeSession_sessionId, _RealtimeSession_ws, _RealtimeSession_expiresAt, _RealtimeSession_logger, _RealtimeSession_task, _RealtimeSession_closing, _RealtimeSession_sendQueue, _RealtimeSession_loggableEvent, _RealtimeSession_start, _RealtimeSession_getContent, _RealtimeSession_handleError, _RealtimeSession_handleSessionCreated, _RealtimeSession_handleSessionUpdated, _RealtimeSession_handleConversationCreated, _RealtimeSession_handleInputAudioBufferCommitted, _RealtimeSession_handleInputAudioBufferCleared, _RealtimeSession_handleInputAudioBufferSpeechStarted, _RealtimeSession_handleInputAudioBufferSpeechStopped, _RealtimeSession_handleConversationItemCreated, _RealtimeSession_handleConversationItemInputAudioTranscriptionCompleted, _RealtimeSession_handleConversationItemInputAudioTranscriptionFailed, _RealtimeSession_handleConversationItemTruncated, _RealtimeSession_handleConversationItemDeleted, _RealtimeSession_handleResponseCreated, _RealtimeSession_handleResponseDone, _RealtimeSession_handleResponseOutputItemAdded, _RealtimeSession_handleResponseOutputItemDone, _RealtimeSession_handleResponseContentPartAdded, _RealtimeSession_handleResponseContentPartDone, _RealtimeSession_handleResponseTextDelta, _RealtimeSession_handleResponseTextDone, _RealtimeSession_handleResponseAudioTranscriptDelta, _RealtimeSession_handleResponseAudioTranscriptDone, _RealtimeSession_handleResponseAudioDelta, _RealtimeSession_handleResponseAudioDone, _RealtimeSession_handleResponseFunctionCallArgumentsDelta, _RealtimeSession_handleResponseFunctionCallArgumentsDone, _RealtimeSession_handleRateLimitsUpdated;
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.

@@ -102,3 +102,3 @@ //

export class RealtimeModel extends multimodal.RealtimeModel {
constructor({ modalities = ['text', 'audio'], instructions = undefined, voice = 'alloy', inputAudioFormat = 'pcm16', outputAudioFormat = 'pcm16', inputAudioTranscription = { model: 'whisper-1' }, turnDetection = { type: 'server_vad' }, temperature = 0.8, maxResponseOutputTokens = undefined, model = 'gpt-4o-realtime-preview-2024-10-01', apiKey = process.env.OPENAI_API_KEY || '', baseURL = api_proto.API_URL, }) {
constructor({ modalities = ['text', 'audio'], instructions = '', voice = 'alloy', inputAudioFormat = 'pcm16', outputAudioFormat = 'pcm16', inputAudioTranscription = { model: 'whisper-1' }, turnDetection = { type: 'server_vad' }, temperature = 0.8, maxResponseOutputTokens = Infinity, model = 'gpt-4o-realtime-preview-2024-10-01', apiKey = process.env.OPENAI_API_KEY || '', baseURL = api_proto.API_URL, }) {
super();

@@ -152,4 +152,3 @@ this.sampleRate = api_proto.SAMPLE_RATE;

async close() {
// TODO: Implement close method
throw new Error('Not implemented');
await Promise.allSettled(__classPrivateFieldGet(this, _RealtimeModel_sessions, "f").map((session) => session.close()));
}

@@ -167,2 +166,3 @@ }

_RealtimeSession_ws.set(this, null);
_RealtimeSession_expiresAt.set(this, null);
_RealtimeSession_logger.set(this, log());

@@ -203,2 +203,8 @@ _RealtimeSession_task.set(this, void 0);

}
get expiration() {
if (!__classPrivateFieldGet(this, _RealtimeSession_expiresAt, "f")) {
throw new Error('session not started');
}
return __classPrivateFieldGet(this, _RealtimeSession_expiresAt, "f") * 1000;
}
queueMsg(command) {

@@ -241,3 +247,5 @@ __classPrivateFieldGet(this, _RealtimeSession_sendQueue, "f").put(command);

temperature: __classPrivateFieldGet(this, _RealtimeSession_opts, "f").temperature,
max_response_output_tokens: __classPrivateFieldGet(this, _RealtimeSession_opts, "f").maxResponseOutputTokens,
max_response_output_tokens: __classPrivateFieldGet(this, _RealtimeSession_opts, "f").maxResponseOutputTokens === Infinity
? 'inf'
: __classPrivateFieldGet(this, _RealtimeSession_opts, "f").maxResponseOutputTokens,
tools,

@@ -249,7 +257,10 @@ tool_choice: toolChoice,

async close() {
// TODO: Implement close method
throw new Error('Not implemented');
if (!__classPrivateFieldGet(this, _RealtimeSession_ws, "f"))
return;
__classPrivateFieldSet(this, _RealtimeSession_closing, true, "f");
__classPrivateFieldGet(this, _RealtimeSession_ws, "f").close();
await __classPrivateFieldGet(this, _RealtimeSession_task, "f");
}
}
_RealtimeSession_fncCtx = new WeakMap(), _RealtimeSession_opts = new WeakMap(), _RealtimeSession_pendingResponses = new WeakMap(), _RealtimeSession_sessionId = new WeakMap(), _RealtimeSession_ws = new WeakMap(), _RealtimeSession_logger = new WeakMap(), _RealtimeSession_task = new WeakMap(), _RealtimeSession_closing = new WeakMap(), _RealtimeSession_sendQueue = new WeakMap(), _RealtimeSession_instances = new WeakSet(), _RealtimeSession_loggableEvent = function _RealtimeSession_loggableEvent(event, maxLength = 30) {
_RealtimeSession_fncCtx = new WeakMap(), _RealtimeSession_opts = new WeakMap(), _RealtimeSession_pendingResponses = new WeakMap(), _RealtimeSession_sessionId = new WeakMap(), _RealtimeSession_ws = new WeakMap(), _RealtimeSession_expiresAt = new WeakMap(), _RealtimeSession_logger = new WeakMap(), _RealtimeSession_task = new WeakMap(), _RealtimeSession_closing = new WeakMap(), _RealtimeSession_sendQueue = new WeakMap(), _RealtimeSession_instances = new WeakSet(), _RealtimeSession_loggableEvent = function _RealtimeSession_loggableEvent(event, maxLength = 30) {
const untypedEvent = {};

@@ -281,3 +292,3 @@ for (const [key, value] of Object.entries(event)) {

__classPrivateFieldGet(this, _RealtimeSession_ws, "f").onerror = (error) => {
reject(error.message);
reject(error);
};

@@ -392,4 +403,7 @@ await once(__classPrivateFieldGet(this, _RealtimeSession_ws, "f"), 'open');

__classPrivateFieldGet(this, _RealtimeSession_ws, "f").onclose = () => {
if (__classPrivateFieldGet(this, _RealtimeSession_expiresAt, "f") && Date.now() >= __classPrivateFieldGet(this, _RealtimeSession_expiresAt, "f") * 1000) {
__classPrivateFieldSet(this, _RealtimeSession_closing, true, "f");
}
if (!__classPrivateFieldGet(this, _RealtimeSession_closing, "f")) {
reject('OpenAI Realtime connection closed unexpectedly');
reject(new Error('OpenAI Realtime connection closed unexpectedly'));
}

@@ -409,2 +423,4 @@ __classPrivateFieldSet(this, _RealtimeSession_ws, null, "f");

__classPrivateFieldSet(this, _RealtimeSession_sessionId, event.session.id, "f");
__classPrivateFieldSet(this, _RealtimeSession_expiresAt, event.session.expires_at, "f");
__classPrivateFieldSet(this, _RealtimeSession_logger, __classPrivateFieldGet(this, _RealtimeSession_logger, "f").child({ sessionId: __classPrivateFieldGet(this, _RealtimeSession_sessionId, "f") }), "f");
}, _RealtimeSession_handleSessionUpdated = function _RealtimeSession_handleSessionUpdated(event) { }, _RealtimeSession_handleConversationCreated = function _RealtimeSession_handleConversationCreated(event) { }, _RealtimeSession_handleInputAudioBufferCommitted = function _RealtimeSession_handleInputAudioBufferCommitted(event) {

@@ -411,0 +427,0 @@ this.emit('input_speech_committed', {

{
"name": "@livekit/agents-plugin-openai",
"version": "0.3.0",
"version": "0.3.1",
"description": "OpenAI plugin for LiveKit Node Agents",

@@ -17,3 +17,3 @@ "main": "dist/index.js",

"ws": "^8.16.0",
"@livekit/agents": "0.3.0"
"@livekit/agents": "0.3.1"
},

@@ -20,0 +20,0 @@ "scripts": {

@@ -86,12 +86,8 @@ // SPDX-FileCopyrightText: 2024 LiveKit, Inc.

export type TurnDetectionType =
| {
type: 'server_vad';
threshold?: number; // 0.0 to 1.0, default: 0.5
prefix_padding_ms?: number; // default: 300
silence_duration_ms?: number; // default: 200
}
| {
type: 'none';
};
export type TurnDetectionType = {
type: 'server_vad';
threshold?: number; // 0.0 to 1.0, default: 0.5
prefix_padding_ms?: number; // default: 300
silence_duration_ms?: number; // default: 200
};

@@ -180,12 +176,13 @@ export type InputAudioTranscription = {

modalities: ['text', 'audio'] | ['text']; // default: ["text", "audio"]
instructions?: string; // default: null
instructions: string;
voice: Voice; // default: "alloy"
input_audio_format: AudioFormat; // default: "pcm16"
output_audio_format: AudioFormat; // default: "pcm16"
input_audio_transcription?: InputAudioTranscription; // default: null
turn_detection: TurnDetectionType;
input_audio_transcription: InputAudioTranscription | null;
turn_detection: TurnDetectionType | null;
tools: Tool[];
tool_choice: ToolChoice; // default: "auto"
temperature: number; // default: 0.8
max_response_output_tokens: number | null;
max_response_output_tokens: number | 'inf';
expires_at: number;
}

@@ -243,8 +240,8 @@

output_audio_format: AudioFormat;
input_audio_transcription?: InputAudioTranscription;
turn_detection: TurnDetectionType;
input_audio_transcription: InputAudioTranscription | null;
turn_detection: TurnDetectionType | null;
tools: Tool[];
tool_choice: ToolChoice;
temperature: number;
max_response_output_tokens: number;
max_response_output_tokens: number | 'inf';
}>;

@@ -324,3 +321,3 @@ }

temperature: number;
max_response_output_tokens: number;
max_output_tokens: number | 'inf';
}>;

@@ -327,0 +324,0 @@ }

@@ -13,10 +13,10 @@ // SPDX-FileCopyrightText: 2024 LiveKit, Inc.

modalities: ['text', 'audio'] | ['text'];
instructions?: string;
instructions: string;
voice: api_proto.Voice;
inputAudioFormat: api_proto.AudioFormat;
outputAudioFormat: api_proto.AudioFormat;
inputAudioTranscription?: api_proto.InputAudioTranscription;
turnDetection: api_proto.TurnDetectionType;
inputAudioTranscription: api_proto.InputAudioTranscription | null;
turnDetection: api_proto.TurnDetectionType | null;
temperature: number;
maxResponseOutputTokens?: number;
maxResponseOutputTokens: number;
model: api_proto.Model;

@@ -188,3 +188,3 @@ apiKey: string;

modalities = ['text', 'audio'],
instructions = undefined,
instructions = '',
voice = 'alloy',

@@ -196,3 +196,3 @@ inputAudioFormat = 'pcm16',

temperature = 0.8,
maxResponseOutputTokens = undefined,
maxResponseOutputTokens = Infinity,
model = 'gpt-4o-realtime-preview-2024-10-01',

@@ -261,4 +261,4 @@ apiKey = process.env.OPENAI_API_KEY || '',

outputAudioFormat?: api_proto.AudioFormat;
inputAudioTranscription?: api_proto.InputAudioTranscription;
turnDetection?: api_proto.TurnDetectionType;
inputAudioTranscription?: api_proto.InputAudioTranscription | null;
turnDetection?: api_proto.TurnDetectionType | null;
temperature?: number;

@@ -287,5 +287,4 @@ maxResponseOutputTokens?: number;

async close(): Promise<void> {
// TODO: Implement close method
throw new Error('Not implemented');
async close() {
await Promise.allSettled(this.#sessions.map((session) => session.close()));
}

@@ -300,2 +299,3 @@ }

#ws: WebSocket | null = null;
#expiresAt: number | null = null;
#logger = log();

@@ -348,2 +348,9 @@ #task: Promise<void>;

get expiration(): number {
if (!this.#expiresAt) {
throw new Error('session not started');
}
return this.#expiresAt * 1000;
}
queueMsg(command: api_proto.ClientEvent): void {

@@ -400,4 +407,4 @@ this.#sendQueue.put(command);

outputAudioFormat?: api_proto.AudioFormat;
inputAudioTranscription?: api_proto.InputAudioTranscription;
turnDetection?: api_proto.TurnDetectionType;
inputAudioTranscription?: api_proto.InputAudioTranscription | null;
turnDetection?: api_proto.TurnDetectionType | null;
temperature?: number;

@@ -442,3 +449,6 @@ maxResponseOutputTokens?: number;

temperature: this.#opts.temperature,
max_response_output_tokens: this.#opts.maxResponseOutputTokens,
max_response_output_tokens:
this.#opts.maxResponseOutputTokens === Infinity
? 'inf'
: this.#opts.maxResponseOutputTokens,
tools,

@@ -460,3 +470,3 @@ tool_choice: toolChoice,

this.#ws.onerror = (error) => {
reject(error.message);
reject(error);
};

@@ -575,4 +585,7 @@

this.#ws.onclose = () => {
if (this.#expiresAt && Date.now() >= this.#expiresAt * 1000) {
this.#closing = true;
}
if (!this.#closing) {
reject('OpenAI Realtime connection closed unexpectedly');
reject(new Error('OpenAI Realtime connection closed unexpectedly'));
}

@@ -585,5 +598,7 @@ this.#ws = null;

async close(): Promise<void> {
// TODO: Implement close method
throw new Error('Not implemented');
async close() {
if (!this.#ws) return;
this.#closing = true;
this.#ws.close();
await this.#task;
}

@@ -604,2 +619,4 @@

this.#sessionId = event.session.id;
this.#expiresAt = event.session.expires_at;
this.#logger = this.#logger.child({ sessionId: this.#sessionId });
}

@@ -606,0 +623,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet