fromJson static method

RealtimeConversationItem fromJson(
  1. Map<String, dynamic> m
)

Implementation

static RealtimeConversationItem fromJson(Map<String, dynamic> m) {
  /* ---------- local helper – clone of the parser you already use -------- */
  switch (m['type']) {
    case 'message':
      return RealtimeMessageItem(
        id: m['id'],
        role: m['role'],
        status: m['status'] ?? 'completed',
        content: (m['content'] as List)
            .map<RealtimeMessageContent>((m) => RealtimeMessageContent.fromJson(m as Map<String, dynamic>))
            .toList(),
      );
    case 'function_call':
      return RealtimeFunctionCall(
        id: m['id'],
        name: m['name'],
        arguments: m['arguments'],
        callId: m['call_id'],
        status: m['status'] ?? 'in_progress',
      );
    case 'mcp_call':
      return RealtimeMcpCall(
        id: m['id'],
        name: m['name'],
        arguments: m['arguments'],
        serverLabel: m['server_label'],
        error: m['error'] == null ? null : McpError.fromJson(m['error']),
        output: m['output'],
      );

    case 'mcp_list_tools':
      return RealtimeMcpListTools(
        id: m['id'],
        serverLabel: m['server_label'],
        tools: (m['tools'] as List).cast<Map<String, dynamic>>().map(MCPListToolItem.fromJson).toList(),
        error: m['error'],
      );
    case 'mcp_approval_request':
      return RealtimeMcpApprovalRequest(
        id: m['id'],
        arguments: m['arguments'],
        name: m['name'],
        serverLabel: m['server_label'],
      );
    case 'mcp_approval_response':
      return RealtimeMcpApprovalResponse(
        approvalRequestId: m['approval_request_id'],
        approve: m['approve'],
        id: m['id'],
        reason: m['reason'],
      );
    case 'function_call_output':
      return RealtimeFunctionCallOutput(
        id: m['id'],
        callId: m['call_id'],
        output: m['output'],
        status: m['status'] ?? 'completed',
      );
    default:
      throw ArgumentError('Unknown item type "${m['type']}"');
  }
}