Metatell AI Bot - v0.0.10
    Preparing search index...

    Module @metatell/bot-realtime

    @metatell/bot-realtime

    MetaTell Botのリアルタイム通信レイヤー。LiveKitを使用したWebRTC通信とテスト用モックアダプターを提供します。

    • Node.js 20 以上(推奨: 22+)
    • TypeScript 5.0+
    npm install @metatell/bot-realtime
    # または
    pnpm add @metatell/bot-realtime
    # または
    yarn add @metatell/bot-realtime
    import { LiveKitAdapter } from '@metatell/bot-realtime';

    // アダプター作成
    const adapter = new LiveKitAdapter();

    // イベントリスナー
    adapter.on((event) => {
    switch (event.type) {
    case 'state':
    console.log('接続状態:', event.state);
    break;
    case 'data':
    console.log('データ受信:', event.topic, event.payload);
    break;
    case 'participant-joined':
    console.log('ユーザー参加:', event.identity);
    break;
    }
    });

    // 接続
    await adapter.connect({
    url: 'wss://livekit.example.com',
    tokenProvider: async () => getAccessToken(),
    topics: ['control', 'events', 'transcript'],
    audioPublish: {
    sampleRate: 48000,
    channels: 1
    }
    });

    // データ送信
    await adapter.send('control', JSON.stringify({ action: 'spawn' }));

    // 音声配信
    await adapter.startAudioPublisher();
    await adapter.pushPcmFrame(pcmData);

    本番環境用のLiveKit WebRTCアダプター。

    const options = {
    url: 'wss://your-livekit-server.com',
    tokenProvider: async () => {
    // トークン取得ロジック
    return token;
    },
    topics: ['control', 'events', 'transcript', 'audio'],
    audioPublish: {
    sampleRate: 48000, // 48kHz, 24kHz, または 16kHz
    channels: 1, // モノラルまたはステレオ
    }
    };

    テストと開発用のモックアダプター。

    import { MockAdapter } from '@metatell/bot-realtime';

    const mock = new MockAdapter();

    // モック動作の設定
    mock.simulateConnection();
    mock.simulateParticipant('user-123', 'Alice');
    mock.simulateData('events', { type: 'test' });
    type RealtimeEvent =
    | { type: 'state'; state: ConnectionState }
    | { type: 'data'; topic: string; payload: Uint8Array; from?: string }
    | { type: 'participant-joined'; identity: string; sid: string }
    | { type: 'participant-left'; identity: string; sid: string }
    | { type: 'warning'; code: string; message: string }
    | { type: 'error'; code: string; message: string; cause?: unknown }

    MIT

    Modules

    <internal>

    Classes

    MockAdapter
    RealtimeError

    Interfaces

    AttachVoiceOptions
    CreateTransportOptions
    RealtimeOptions
    RealtimeTransport
    VoiceAttachment
    VoiceHandlers
    VoiceMetadata

    Type Aliases

    ConnectionState
    ErrorCode
    RealtimeEvent
    TokenProvider

    Variables

    ErrorCodes

    Functions

    attachVoice
    createRealtimeTransport