/**
 * OpenAI Realtime API Server Event Types
 * サーバーから受信する可能性のあるメッセージタイプの定数定義
 * https://platform.openai.com/docs/api-reference/realtime-server-events/
 */

export const SERVER_EVENT_TYPES = {
  ERROR: "error",

  SESSION_CREATED: "session.created",
  SESSION_UPDATED: "session.updated",

  CONVERSATION_ITEM_CREATED: "conversation.item.created",
  CONVERSATION_ITEM_ADDED: "conversation.item.added",
  CONVERSATION_ITEM_DONE: "conversation.item.done",
  CONVERSATION_ITEM_RETRIEVED: "conversation.item.retrieved",
  CONVERSATION_ITEM_INPUT_AUDIO_TRANSCRIPTION_COMPLETED: "conversation.item.input_audio_transcription.completed",
  CONVERSATION_ITEM_INPUT_AUDIO_TRANSCRIPTION_DELTA: "conversation.item.input_audio_transcription.delta",
  CONVERSATION_ITEM_INPUT_AUDIO_TRANSCRIPTION_SEGMENT: "conversation.item.input_audio_transcription.segment",
  CONVERSATION_ITEM_INPUT_AUDIO_TRANSCRIPTION_FAILED: "conversation.item.input_audio_transcription.failed",
  CONVERSATION_ITEM_TRUNCATED: "conversation.item.truncated",
  CONVERSATION_ITEM_DELETED: "conversation.item.deleted",

  INPUT_AUDIO_BUFFER_COMMITTED: "input_audio_buffer.committed",
  INPUT_AUDIO_BUFFER_SPEECH_STARTED: "input_audio_buffer.speech_started",
  INPUT_AUDIO_BUFFER_SPEECH_STOPPED: "input_audio_buffer.speech_stopped",
  INPUT_AUDIO_BUFFER_TIMEOUT_TRIGGERED: "input_audio_buffer.timeout_triggered",

  // WebRTC 接続でのみ届く再生バッファイベント (0.3.0-dev.47)。
  // stopped = クライアント側の再生バッファが枯渇 ≒ AI の発話を再生し終えた。
  // cleared = クライアントが送った output_audio_buffer.clear が受理された (0.3.0-dev.73)。
  OUTPUT_AUDIO_BUFFER_STARTED: "output_audio_buffer.started",
  OUTPUT_AUDIO_BUFFER_STOPPED: "output_audio_buffer.stopped",
  OUTPUT_AUDIO_BUFFER_CLEARED: "output_audio_buffer.cleared",

  RESPONSE_CREATED: "response.created",
  RESPONSE_DONE: "response.done",
  RESPONSE_OUTPUT_TEXT_DELTA: "response.output_text.delta",
  RESPONSE_OUTPUT_TEXT_DONE: "response.output_text.done",
  RESPONSE_OUTPUT_AUDIO_TRANSCRIPT_DELTA: "response.output_audio_transcript.delta",
  RESPONSE_OUTPUT_AUDIO_TRANSCRIPT_DONE: "response.output_audio_transcript.done",
  RESPONSE_FUNCTION_CALL_ARGUMENTS_DELTA: "response.function_call_arguments.delta",
  RESPONSE_FUNCTION_CALL_ARGUMENTS_DONE: "response.function_call_arguments.done",
};

export default SERVER_EVENT_TYPES;
