Files
assistant/apps/vela-protocol/src/index.cjs

53 lines
1.0 KiB
JavaScript

const PROTOCOL_PACKAGE_NAME = '@vela/protocol';
const SESSION_STATES = Object.freeze(['idle', 'listening', 'thinking', 'speaking']);
const CLIENT_EVENT_TYPES = Object.freeze([
'session.start',
'input_audio.append',
'input_audio.commit',
'response.cancel'
]);
const SERVER_EVENT_TYPES = Object.freeze([
'session.ready',
'session.state',
'transcript.partial',
'transcript.final',
'response.text.delta',
'response.completed',
'error'
]);
function createMessageEnvelope(type, payload) {
return { type, payload };
}
function isMessageEnvelope(value) {
return Boolean(
value &&
typeof value === 'object' &&
typeof value.type === 'string' &&
'payload' in value
);
}
function isClientEventType(type) {
return CLIENT_EVENT_TYPES.includes(type);
}
function isServerEventType(type) {
return SERVER_EVENT_TYPES.includes(type);
}
module.exports = {
PROTOCOL_PACKAGE_NAME,
SESSION_STATES,
CLIENT_EVENT_TYPES,
SERVER_EVENT_TYPES,
createMessageEnvelope,
isMessageEnvelope,
isClientEventType,
isServerEventType
};