Skip to content

Add internal attributes definition helper #1534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ docs/
node_modules/
protocol/
src/proto/
src/room/attributes/
yarn.lock
pnpm-lock.yaml
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { LogLevel, LoggerNames, getLogger, setLogExtension, setLogLevel } from '
import DefaultReconnectPolicy from './room/DefaultReconnectPolicy';
import type { ReconnectContext, ReconnectPolicy } from './room/ReconnectPolicy';
import Room, { ConnectionState } from './room/Room';
import * as attributes from './room/attribute-typings';
import LocalParticipant from './room/participant/LocalParticipant';
import Participant, { ConnectionQuality, ParticipantKind } from './room/participant/Participant';
import type { ParticipantTrackPermission } from './room/participant/ParticipantTrackPermission';
Expand Down Expand Up @@ -72,6 +73,8 @@ export type {
} from './room/types';
export * from './version';
export {
/** @internal */
attributes,
ConnectionQuality,
ConnectionState,
CriticalTimers,
Expand Down
61 changes: 61 additions & 0 deletions src/room/attribute-typings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// This file was generated from JSON Schema using quicktype, do not modify it directly.
// The code generation lives at https://github.com/livekit/attribute-definitions
//
// To parse this data:
//
// import { Convert, AgentAttributes, TranscriptionAttributes } from "./file";
//
// const agentAttributes = Convert.toAgentAttributes(json);
// const transcriptionAttributes = Convert.toTranscriptionAttributes(json);

export interface AgentAttributes {
'lk.agent.inputs'?: AgentInput[];
'lk.agent.outputs'?: AgentOutput[];
'lk.agent.state'?: AgentState;
'lk.publish_on_behalf'?: string;
[property: string]: any;
}

export type AgentInput = 'audio' | 'video' | 'text';

export type AgentOutput = 'transcription' | 'audio';

export type AgentState = 'idle' | 'initializing' | 'listening' | 'thinking' | 'speaking';

/**
* Schema for transcription-related attributes
*/
export interface TranscriptionAttributes {
/**
* The segment id of the transcription
*/
'lk.segment_id'?: string;
/**
* The associated track id of the transcription
*/
'lk.transcribed_track_id'?: string;
/**
* Whether the transcription is final
*/
'lk.transcription_final'?: boolean;
[property: string]: any;
}

// Converts JSON strings to/from your types
export class Convert {
public static toAgentAttributes(json: string): AgentAttributes {
return JSON.parse(json);
}

public static agentAttributesToJson(value: AgentAttributes): string {
return JSON.stringify(value);
}

public static toTranscriptionAttributes(json: string): TranscriptionAttributes {
return JSON.parse(json);
}

public static transcriptionAttributesToJson(value: TranscriptionAttributes): string {
return JSON.stringify(value);
}
}
4 changes: 4 additions & 0 deletions src/utils/cloneDeep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ export function cloneDeep<T>(value: T): T {
}

if (typeof structuredClone === 'function') {
if (typeof value === 'object' && value !== null) {
// ensure that the value is not a proxy by spreading it
return structuredClone({ ...value });
}
return structuredClone(value);
} else {
return JSON.parse(JSON.stringify(value)) as T;
Expand Down
Loading